- Home /
Problem sliding down hills (WITH VIDEO)
Hello,
I can't get my character to slide down a hill properly, sort of like a skier/snowboarder. I'd really like to know why my character falls where the red arrow is. He also fell when I tried to use multiple planes in unity to simulate a slope. As soon as he got on a different plane he would die.
Here's a gif of what happens right now. As soon as he hit the new normal he just dies...
![alt text][1] [1]: http://answers.unity3d.com/storage/temp/897-slope_fail.gif
var isGrounded: boolean = false; var hit: RaycastHit; var theRay: Vector3; var currentPos : Transform;
function FixedUpdate () { if(isGrounded) { theRay = transform.TransformDirection(Vector3.down); // Convert from local space to world space
if (Physics.Raycast(transform.position, theRay, hit))
{
transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
}
}
Debug.Log(isGrounded);
Debug.DrawRay(transform.position, theRay, Color.red);
}
function OnCollisionEnter(collision : Collision) { isGrounded = true; }
function OnCollisionExit(collisionInfo : Collision) { isGrounded = false; }
Answer by formidable · May 13, 2012 at 03:12 AM
Fuck yeah I think I got it! The problem is my character would touch the next normal, get its position and leave the ground just enough to start spiraling out of control. I fixed it by zeroing the characters angular velocity as soon as it leaves the ground. I just had to add this little bit of code
function OnCollisionExit(collisionInfo : Collision)
{
isGrounded = false;
// Prevent character from spiraling out of control the second it goes airborn
rigidbody.angularVelocity = Vector3.zero;
}
I still have a lot to do like smoothing out the transition between normals and making the character only able to go forward or backward but that can wait. I've been trying to figure this out for 2 weeks!
I almost forgot. You also have to give the ground a physics material and set the friction combine to $$anonymous$$inimum, dynamic friction, static friction and bounciness to 0. No vlue what the friction combined does but it gets rid of the jittery effect when the character is sliding down
Your answer
Follow this Question
Related Questions
Increasing dynamic friction 1 Answer
Making objects slide 1 Answer
Help with sliding down hills 1 Answer
Rigidbody slides across surface 0 Answers
Rigidbody problem 0 Answers