How to detect which direction a sprite it moving?

Hi, how do I make a sprite that is not user-controlled and that knows what direction it is moving? I am trying to make it face the direction it is moving and change its image accordingly.

1 Like

for a simple orthographic left right up down system just check it’s vx and vy since these are also technically vectors they give both magnitude and direction (forwards or backwards on a line)

if vx is positive it’s moving right
if vx is negative it’s moving left

if vy is positive it’s moving down
if vy is negative it’s moving up

put these into an array of sprites of kind [insert desiredspritekind] if you want it to act for multiple different sprites of the same kind (like enemies)

using the sprite utils extension, you can also measure the velocity angle of a sprite for very precise angles
(and it would also be more optimised code)

oops yeah richard is completely right! use character animations if you’re animating!

4 Likes

if you just want this information for animating sprites, then i’d recommend using the character animations extension!

4 Likes

Ok. Thank you!

2 Likes