- Home /
Character rotates when climbing down a hill/mountain
I'm completely new to Unity3D and have been trying to move my player character on a simple terrain. The character moves fine if its on the plane or moving up a mountain but when it moves towards the plane (down from a mountain), it starts rotating and keeps on rotating till it reaches the ground (because of this sometimes the character can lay flat on the ground).
My character (a simple male character from asset 'Supercayan Character Pack Free') has the following settings:
Also note that if I uncheck the 'Use Gravity' option, the character moves a bit more faster and the animations on it are a bit smoother but I have to check this otherwise the player character will never be able to move downwards along y-axis.
My code for movement is:
// Update is called once per frame
void Update()
{
//walk
if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.RightArrow))
{
//animate walk
animCharacter.SetBool("Walk", true);
animCharacter.SetBool("Stop", false);
}
//stop
if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.DownArrow) || Input.GetKeyUp(KeyCode.RightArrow))
{
animCharacter.SetBool("Walk", false);
animCharacter.SetBool("Stop", true);
}
}
void FixedUpdate()
{
inputVector = new Vector3(Input.GetAxis("Horizontal") * 5f, 0, Input.GetAxis("Vertical") * 5f);
transform.LookAt(transform.position + new Vector3(inputVector.x, 0, inputVector.z));
playerBody.velocity = inputVector;
}
How can I make my character move around the terrain without him floating around?
Answer by suIly · Aug 06, 2019 at 10:28 AM
In the rigidbody inspector, check all of the "Freeze rotation" bools. This will stop the player from rotating on slopes or anything else
It keeps the character from rotating but also stops him from moving up the hill.
Did you check "Freeze Position"? If so, uncheck it
I would also use the capsule collider ins$$anonymous$$d of a box collider, since the edges are curved, and it would be more smooth of a descend or ascend on hills
Thanks, this solved the issue of not ascending on hills.