I made character movement using AddForce. But I don't understand how to get the desired effect. I need that when I release a movement key (for example WASD) the character stops instantly or almost instantly, but when using AddForce it slides for a while after releasing the movement key.
For example
private void FixedUpdate()
{
moveHorizontal = Input.GetAxis("Horizontal");
moveVertical = Input.GetAxis("Vertical");
_direction = new Vector3(moveHorizontal,0, moveVertical);
_rigidbody.AddForce(_direction * _speed);
}
I don't want to change any Rigidbody or gravity properties, because it might cause other problems and affect other objects in the scene.
AccelerateTowardsmethod that applies forces to match a target velocity — including using forces to slow down and stop when the target is zero. This answer shows a simple version. This other answer shows a slightly more elaborate version where you can apply a stronger stopping force, while keeping the acceleration gradual when speeding up \$\endgroup\$