How do I Set the Animation of an Object Based on Y-value?

0 favourites
  • 6 posts
From the Asset Store
Hand-animated Sprite Base for isometric game/animation development
  • I have an object that uses path finding to move. If it is going left I want it to play one animation or if it is going right to play a different animation. I was think of using its Y coordinate do so but I do just can't figure it out.

    In summary I was seeing if I could check the change in the Y coordinate to set the animation (Decreasing for left, Increasing Y for Right)

    I am open to suggestions if you have an alternate method

    Thank you, Nick

  • The Y coordinate represents up and down. Try using the X coordinate.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Whilst I am an idiot for making such a rookie mistake, that sadly did not solve my animation dilemma

  • Save y to a variable LastY every tick. Compare current y to LastY to see which is greater and set the appropriate animation.

  • Alright, try this:

    + Sprite: Is Pathfinding moving along path

    ----+ System: Sprite.Pathfinding.MovingAngle is between 90 and 270 degrees

    -----> Sprite: Set animation to "WalkLeft" (play from beginning)

    ----+ System: Else

    -----> Sprite: Set animation to "WalkRight" (play from beginning)

    Instead of checking the x value, check the move angle. If it is between 90 and 270, the player is facing left. if not, the player is moving right.

  • + Sprite: Is Pathfinding moving along path

    + System: Sprite.Pathfinding.CurrentNode ≠ Sprite.Pathfinding.NodeCount

    ----+ Sprite: X > Self.Pathfinding.NodeXAt(Self.Pathfinding.CurrentNode)

    -----> Sprite: Set animation to "MoveLeft" (play from beginning)

    ----+ System: Else

    -----> Sprite: Set animation to "MoveRight" (play from beginning)

    Here's another option. This one uses the x coordinate if that is easier for you than the angle. Notice the use of the NodeXAt call. This gets the x coordinate of the node whose id you pass in.

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