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.

https://www.dropbox.com/s/djutuim7u7km99z/Puppet%20Movement%20Test.capx

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 :)
B
4
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
B
12
S
4
G
2
Posts: 59
Reputation: 3,799

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.
B
4
Posts: 6
Reputation: 212


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests