Character Controller: Smooth Movement
You want your character to move forward. Easy right? Get the input, multiply it by the speed and call it a day:
|
|
Seems cool, but if you let go of the joystick, the character will come to an immediate stop. This is jarring. We want the character to have some sort of momentum, so they speed up and slow down smoothly. With this, we’re going to need to use forces:
|
|
This looks fine, but we also need to limit the character’s max speed:
|
|
Better. But how long does it take to reach the max speed? We can calculate this with:
|
|
What if we have two max speeds? One for walking and one for sprinting. This means that the time to reach the max speed will change depending on the max speed. I guess that makes sense for something like a car, but for a creature, that doesn’t feel great. We want more control over it.
The solution is to move the velocity toward a target velocity:
|
|
Understanding this will give you silky smooth movement while giving you full control over the max speeds and velocity changes.