MM1: Smooth turn movement
Smoother turn movement for a Godot game | MM1
Problem
Converting WASD into a vector and slapping it into your velocity is ok, but:
- Try open basically anything 3D and press A and D keys fast to see the result. You won't see this
Let's also jump and then run left after the landing → same abrupt transition.
Solution: rotating input direction
- In real life, an object's velocity never changes instantly. It gradually slows down, then flips and grows to the opposite direction, or it saves the speed but quickly turns around.
I don't like linear vector interpolation for movement, but the video's too short to explain why. Think of these two cases I'm showing on the screen.
- Saving speed while gradually changing its direction, on the other hand, is much more real-life-ish.
So instead of taking WASD direction and overriding our speed with it, we will just rotate it.
First version
- code
- First, we calculate the direction input, then character face direction and the difference.
- Then if the difference is bigger than some angular speed value, we rotate our vector by the angular speed.
- If not, we rotate it by difference, compensating it.
Better already, at least it passes the spam test and the head test.
Second version