playMaker

Author Topic: Getting the horizontal direction/rotation/whatever of an object [SOLVED]  (Read 1433 times)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Hi guys, i'm having the problem that has been bothering me since the start of the project, and it's time to put it to an end.

Imagine this little fella is a spaceship with an engine jet behind him.

(]>

They are separate objects for the reason of only ship changing the color when he is hit (sprite masks are too complicated for this).

When the ship is moving from right to left, i set it's scale properly be getting if he's beyond a certain x position and the jet is rotated towards right. That's ok. When it's moving from left to right, i set the x scale of the ship to -1, the jet detects if engine is -x, and flips too.

But, there are certain situations when the rule is unnaplicable. Like when ship is spawned in the middle of the screen (from a carrier for example), and though the spawn location indicates one jet position, it should be placed on the other side.

There are lots of exceptions, too much to cover in a simple way.

I tried using Get Forward Direction, Get Speed, Get Velocity to get some parameters that could help me out, but i get nothing because the ships are moving either by tweening or by translate.

One idea i'm having is to get the x position of a ship and the position on the next frame and then compare them. If the new float is lower, ship is moving left, if it's higher, then it's moving right and the jet can be rotated accordingly. Unfortunately, this is also unnaplicable for the ship that are rotated either left or right but move only up or down.

Any good ideas on this one, i'm pulling my hair out for months.
« Last Edit: February 20, 2018, 05:51:43 AM by krmko »
Available for Playmaker work

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Getting the horizontal direction/rotation/whatever of an object
« Reply #1 on: February 19, 2018, 02:25:05 AM »
Hi,

 GetSpeed is the closest thing that will give you the direction at a given time. from the direction, you can then deduce how to flip things around. But the problem with this is indeed when the ship is not moving...

 I would carefully consider how many cases you have, you might find it's not that much. and I would create a system that the ship could query to know how to setup itself based on the current context.

Bye,

 Jean


Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Getting the horizontal direction/rotation/whatever of an object
« Reply #2 on: February 19, 2018, 02:45:45 AM »
Well, get speed gets me nothing. As far as i have seen it gets the rigidbody velocity, but since i'm not using any physics for movement, just translate, i get nothing. I guess getting the movement speed of the rigidbody that moves by translate is same as i figured it out, getting the previous and current position and comparting that with time.
Available for Playmaker work

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Getting the horizontal direction/rotation/whatever of an object
« Reply #3 on: February 20, 2018, 02:05:43 AM »
Hi,

 Then, use GetGameObjectSpeed from the Ecosystem, it works for non RigidBody GameObjects.

 Bye,

 Jean

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Getting the horizontal direction/rotation/whatever of an object
« Reply #4 on: February 20, 2018, 05:32:23 AM »
Excellent, thank you.
Available for Playmaker work