I’m running into that typical beginner issue of my player “Sliding on Ice” when I move. It feels like he’s moving on a really slippery surface and it’s not realistic.
I’m using a Rigidbody and Capsule Collider on my character. He moves with rb.AddForce and this works fine because it gives the sort of realistic movement I want, however it just keeps him sliding. I have clamped the max speed in code so the velocity doesn’t continue adding past a certain number. I would like the player to still move a little when you let go of the move input, but not just slide around.
I don’t know if this is an issue in code or something in the physics.
public float moveSpeed = 15f;
public float maxSpeed = 20f;
private void Move()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if (direction.magnitude >= 0.001 && rb.velocity.magnitude <= maxSpeed)
{
//to get him to move, rotate and face the direction of the 3rd person camera
float targetAngle = Mathf.Atan2(horizontal, vertical) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVel, turnSmooth);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
transform.rotation = Quaternion.Euler(0f, angle, 0f);
//movement physics
rb.AddForce(moveSpeed * moveDir);
}
}
All help appreciated, thanks
1 Like
You set direction equal to a normalised vector, so its magnitude will always be 1, so the following check for direction.magnitude >= 0.001 will always be true.
You then always add force equal to direction * moveSpeed
Just an additional thing to consider… A moving object will continue to move at a constant velocity until an opposing force slows/stops it. That force may be drag, friction or an opposing addForce, but it won’t just stop moving when you stop applying the force.
1 Like
Just an extra point… you can call your variables what you like, but the variable you have called moveSpeed is being used as a force, which might cause some confusion. Check out
and follow it to
1 Like
Ah thank you for your solutions. Yes I’ve been considering changing it to moveForce. Thanks!
1 Like
just increase ur rigidbody’s drag variable
1 Like
I would suggest moving the center of mass upwards and downwards depending on your action if you want “slippery” like ice, but not slippery like no gravity. And as the others mention you need to use drag and angular drag, you might also want to increase solver iterations and solver velocity iterations if you’re using ice with IK/FK-Limbs such that the simulation of limbs during a fall wont look too crazy, if its realism you aim for. having bunkers reactions to ragdolls can be very entertaing too. Any way do as suggested, and move center of mass if you want to be able to fall or not fall depending on motion as well, but ultimately Drag, and Angular Drag is what gets you inertia and slowing over time. For the latter you can also look into friction and physics materials which you can apply to the surface. Those are the key most important things.
Oh specifically to keep inertia, do not use rotate, but torques, its like not using move, and instead using addforce, but for rotation 
2 Likes