- Home /
My capsule character tilts when climbing stairs.
I use capsule as a 3D character on my game and it tilts easily and also it can not climb the stairs. I don't know how to make my capsule character climb stairs without tilting or rolling. (I'm using rigidbody velocity to move my agent.)
public class karakterkodları : MonoBehaviour
{
Rigidbody fizik;
float horizontal = 0;
float vertical = 0;
Vector3 vec;
public float hiz;
void Start()
{
fizik = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical")*-1;
vec = new Vector3(vertical*hiz, 0, horizontal*hiz);
fizik.velocity = vec;
}
}
Answer by medyahan · Oct 24, 2020 at 10:41 AM
You can try to open the x, y and z axes from the freeze rotation section in the constraints options on your character's rigidbody. In this way, the rotation of the character will remain constant.
@medyahan thx for that and I also wonder how can I adjust my character to climb stairs
I am glad I could help :) So which component do you use for the player? Character Controller or rigidbody. If you are using rigidbody I suggest you use the character controller. Because you can climb objects like stairs with the step offset value
Answer by ozgunn · Oct 24, 2020 at 12:57 PM
I appreciate again @medyahan . Last question is how to convert this script for CharacterController component ? Thanks over and over again.
{
Rigidbody fizik;
float horizontal = 0;
float vertical = 0;
Vector3 vec;
public float hiz;
void Start()
{
fizik = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical")*-1;
vec = new Vector3(vertical*hiz, 0, horizontal*hiz);
fizik.velocity = vec;
}
} `
First Solution: This video will help you to use character controller. Between 2.36 and 9.10 $$anonymous$$utes..
https://www.youtube.com/watch?v=59No0ybIoxg&t=1012s
Second Solution: If you will continue to use Rigidbody, you can try to replace the stairs collider with a sloped collider. But I suggest you use the character controller
Your answer
Follow this Question
Related Questions
Why can't the Physics Locomotion System walk up stairs/inclines? 2 Answers
Unity 5.0 Physics Freeze rotation not working 5 Answers
When jump my character controller model it goes out of collider 0 Answers
Capsule Collider not moving with the character 0 Answers
Is there a rigidbody character controller 3rd person that can handel stairs (steps)? 1 Answer