I am attempting to rotate a mesh in the direction it is moving, but no matter what I try, I can not get it to work properly. I have been using the “lerp_angle()” method, but am struggling to figure out what the second input should be. This is all potentially relevant parts of the script I am using.
I added in the “input_dir.angle()” as suggested, but am still faced by some issues. As is, the script would make the mesh’s rotation equal to zero when there was no input. This was fixed by wrapping the line in this if condition, but there are still an issue: the rotation stops abruptly if the input is released during the rotation. How could I fix this?
The edited code as is:
if input_dir.angle() !=0 or Input.is_action_pressed("move_right"):
model.rotation.y = lerp_angle(model.rotation.y, input_dir.angle() * -1, delta * 12)
Maybe you could use the angle of the velocity, flattened
var planar_velocity := Vector2(velocity.x, velocity.z)
if not planar_velocity.is_zero_approx():
model.rotation.y = lerp_angle(model.rotation.y, planar_velocity.angle(), delta * 12)