0 Favourites

Get a sprite to face the direction it's moving

  • 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.

    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 :)

  • 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.Y

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Thanks David, took a bit more fiddling to sort out some other stuff but it seems to work now.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)