Point my sprite towards the direction the player is moving

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tproper

I am using the simple Icon.png that came with Godot.

I created a player with that Icon that I can move. I want to rotate the top of the sprite to face the direction the player is moving so that it looks like the sprite is turning/walking with the velocity I am applying to it.

In the future, I’ll be using a sprite of a walking person or something but as of now I just want to see how I’d go about rotating the sprite to point towards the direction of the velocity.

How can I do this?

:bust_in_silhouette: Reply From: kidscancode

Another option if you have a velocity vector already that you’re using for movement is:

rotation = velocity.angle()

Thanks! That worked.

tproper | 2018-05-10 21:09

Hey. This worked for me to.
But I’m trying to make it do a smooth transition. I tried using a Tween node but it doesn’t tween over the shortest angle. It makes my sprite spin 315 deg clockwise instead of 45 in the anti-clockwise direction.

Leon Oscar Kidando | 2019-05-06 12:36

you could use a lerp

rotation = lerp(rotation,velocity.angle(),0.1)

IconicPrefix | 2021-01-27 16:32

I’d recomend using lerp_angle so

rotation = lerp_angle(rotation,velocity.angle(),0.1)

TigerFighter102 | 2022-12-07 04:24

1 Like