playMaker

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

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 1037
    • View Profile
    • 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, 03:51:43 AM by krmko »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14833
  • Official Playmaker Support
    • View Profile
Re: Getting the horizontal direction/rotation/whatever of an object
« Reply #1 on: February 19, 2018, 12: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


krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 1037
    • View Profile
    • Fat Pug Studio
Re: Getting the horizontal direction/rotation/whatever of an object
« Reply #2 on: February 19, 2018, 12: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.

jeanfabre

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

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

 Bye,

 Jean

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 1037
    • View Profile
    • Fat Pug Studio
Re: Getting the horizontal direction/rotation/whatever of an object
« Reply #4 on: February 20, 2018, 03:32:23 AM »
Excellent, thank you.