Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to know in which direction an object is moving?

So, I have an Enemy that move in a certain direction and I need to play a different animation for each direction.


Question: How can I know in which direction the Enemy is moving?

Best Answer

  • CopperCopper Member
    Accepted Answer

    If your enemy is moving either to the left or the right, you can make a boolean that is true if the enemy is facing right and false if it's facing left. You can update it by checking if the enemy's current position on the x axis is greater or smaller than on the frame before.

    If the two different animations are otherwise identical but just flipped, I would recommend simply changing the x scale of the enemy to -1. This flips the sprite.

Answers

  • Sorry, my bad, I didn't write that the game is in 3D, but i think the concept of comparing the position between frames is the same, only in both x, z.

    Anyway thank you for anwering ;D

Sign In or Register to comment.