- Home /
Need help with slope movement
Hey so i am trying to prevent the rigidbody from sliding down slopes when not moving the problem is as soon as i stop moving i bounce up a bit like shown here if anyone has an idea of what could resolve the problem i would mean so much
//Stops player from sliding when not moving on a slope
if (playerScript.inputScript.input.x == 0 && playerScript.inputScript.input.y == 0)
{
print("stopping on slope");
Vector3 slopeGravity = Physics.gravity * playerScript.rb.mass;
playerScript.rb.AddForce(-slopeGravity);
}
Comment
Best Answer
Answer by DenisIsDenis · Jun 26, 2021 at 10:11 AM
gravity
is a downward vector (default). And when you write playerScript.rb.AddForce (-slopeGravity);
in fact, you flip this vector directing it up. Try
playerScript.rb.AddForce (slopeGravity);
If you want to stop sliding, you can reset velocity.x
and velocity.z
:
var velocity = playerScript.rb.velocity;
velocity.x = 0;
velocity.z = 0;
playerScript.rb.velocity = velocity;
Your answer
