Get a sprite to face the direction it's moving

Get help using Construct 2

Post » Thu Jul 25, 2013 4:55 pm

Hey guys,

I've been trying to get a Sprite to face the general direction it's moving as it moves along a pathfinding path.

Initially when I was just using a simple sprite I just used Mirror based on the X location of the touch. But for some reason I can't use Mirror successfully with objects that are pinned together.

I've hooked up a test space below, and sometimes the base sprite will face the correct location but in other cases it will keep facing one direction until you define a second path.

I was hoping to have a solution that kept track of the X position as it moved along the path but it flips like crazy, probably something is happening every tick but i'm not sure what.

Is there a solution I can use to iterate through the nodes? For instances where the pathfinding causes the sprite to double back on itself along its new path.

Any help would be much appreciated :)
Posts: 6
Reputation: 212

Post » Thu Jul 25, 2013 6:31 pm

Simple. All you need to do is create two instance variables for your sprite. Let's say Old_X and Old_Y

Now every tick you first compare;

is Old_X < X? then set Not Mirrored
is Old_X > X? then set Mirrored

(this might be reversed depending on which way the sprite is defaulted)

then set;

Old_X = Sprite.X
Old_Y = Sprite.YDavid Flook2013-07-25 18:32:05
Posts: 59
Reputation: 3,879

Post » Mon Jul 29, 2013 4:26 pm

Thanks David, took a bit more fiddling to sort out some other stuff but it seems to work now.
Posts: 6
Reputation: 212

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 51 guests