# How to stop sliding properly

I wanna stop immediately (not instantly) when I release a key so it would not slide. I don't wanna use rb.isKinematic = false; because it's just stopping so instant. So like I thought about:

x = GetAxisRaw("Horizontal");
z = GetAxisRaw("Vertical");

move = transform.right * x + transform.forward * z;

if (no inputs pressed)
{
rb.AddForce(force * -maxSpeed); // maybe force will be the current velocity
}


I tried this but seems like nothing is hapenning. And so I think I need some improvements

• What is the difference between immediately and instantly? Dec 29 '20 at 15:38
• Sorry about that, what I mean by immediately is slowly stop like around less than 0.1s, and what I mean by instantly is just stop in 0s Dec 29 '20 at 15:54
• Increasing the friction of your object is not working for you? Dec 29 '20 at 16:11
• I added a physics material on it just now, which had static friction = 1 and dynamic friction to 1, and set the friction combine to maxinum but my player can't move. Did I assigned the variables correctly? Dec 29 '20 at 16:19
• Dynamic Friction: The friction used when already moving. Usually a value from 0 to 1. A value of zero feels like ice, a value of 1 will make it come to rest very quickly unless a lot of force or gravity pushes the object. Static Friction: The friction used when an object is laying still on a surface. Usually a value from 0 to 1. A value of zero feels like ice, a value of 1 will make it very hard to get the object moving. docs.unity3d.com/Manual/class-PhysicMaterial.html Dec 29 '20 at 16:25

You can use Unity’s rigidbody object to modify the drag property, which is used to modify the rate that an object slows down when not acted upon by outside forces.

Either that, or if you wanted to get down and dirty, simply do

velocity = velocity * 0.979;


every update tick when you would like to slow the object. Adjust the numerical value between 0 and 1 to achieve your desired rate of deceleration.

Drag is one of the most difficult things to model accurately. There are many different equations we use to model drag in the real world (it gets extremely complex) but typically for real time simulation in games, highly simplified versions are used. In the examples provided by this discussion, you can see that some people (and most physics engines) model drag using a quadratic value. This is perhaps more realistic, but not required to achieve the results you may be looking for.

I believe the equation for the force of drag they teach in beginner physics classes is typically Fdrag = -v * b where b is some constant value. This is essentially what you already had, but is a less desirable solution in games. In the end, choose the method that feels best for your project.

• how does drag works? Is it the higher the value the lower speed it will go down? I see on the documentation it is said OpenParachute() and set the drag value to 20 Dec 30 '20 at 11:07
• @AdolfJamesUrian “The higher the drag the more the object slows down” is the description
– Jon
Dec 30 '20 at 11:09