This is in context of 2D top-down game, where player sees everything from above. This is somewhat extension of topic I’ve made earlier, but I think snapping to it instantly using LookAt doesn’t look as good as I’ve expected.
I want player character to face the mouse cursor, but not snap to it instantly, just smoothly slowly rotate to proper position.
Player character doesn’t face the cursor from the front, but from the right side.
Sometimes player instead of rotating just a little, does 360 degrees spin.
The first issue comes from the fact that engine considers front of the character to be x = 1 y = 0. For me front of the character is x = 0 y = -1. I don’t know how to compensate for it.
The second issue comes from the fact that at very specific radian value is some kind of deadzone that engine doesn’t like, and instead of going past that point, it just goes around. Again, I don’t know how to solve it.
I’ve made a sketch to show the issue. Left is expected behavior, right is real behavior, and image how player character (the triangle thingy) looks like on Godot 2D axes:
If you want a smooth approach you can use the lerp()-method.
to get the correct angle you can just call:
GlobalPosition.angle_to(GetGlobalMousePosition) - Pathf.Pi/2 # - pi/2 to consider the front of the camera
# either move_toward or lerp
Rotation = Mathf.Lerp(Rotation, targetRotation, 0.1);
About the problem with going around the wrong way: the issue is that you are setting the rotation, instead you should add/subtract the difference in angles