- Home /
Character sliding over terrain.
My 3d character slides down when terrain have a little inclination. I want to stop this. This is my script to control character movement:
float rotation;
public float MoveSpeed = 3;
public Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent <Rigidbody>();
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.LeftShift)) {
MoveSpeed += 2;
} else {
MoveSpeed = 3;
}
if (Input.GetKeyDown (KeyCode.Space)) {
rb.velocity = new Vector3 (0.0f, 5, 0.0f);
}
rotation += PlayerCamera.speedH * Input.GetAxis ("Mouse X");
transform.eulerAngles = new Vector3 (0.0f, rotation, 0.0f);
transform.Translate (Vector3.right * Input.GetAxis ("Horizontal") * MoveSpeed * Time.deltaTime);
transform.Translate (Vector3.forward * Input.GetAxis ("Vertical") * MoveSpeed * Time.deltaTime);
}
void OnTriggerEnter (Collider col) {
transform.Translate (new Vector3 (transform.position.x, transform.position.y, transform.position.z));
}
Answer by fametune · Apr 02, 2018 at 04:59 PM
I had the same problem recently. After changing my characters capsule collider's material to FrictionPhysicsMaterial, the sliding finally stopped and I could keep it in place at slightly angled surfaces.
Hope this helps
Answer by amaterasw2 · Jul 08, 2020 at 05:24 PM
Change the collider plane vector y to a more much number.
Your answer
Follow this Question
Related Questions
Terrain, Player falls through.... but only some parts. 0 Answers
Animating character around terrain on preprogrammed route without players control 0 Answers
Character Controller Lands on Slopes 2 Answers
Kinect issue with Character Movement while in flight 0 Answers
How to move Character along world floor? 2 Answers