- Home /
Character controller is shaky/jittery
Hey Guys, Im using the code below to make the character move. It automatically jumps when it lands on platforms but it shakes/jitters specially when the player is going down and i cant work out why.. The character is a cube and doesnt have any extra colliders besides character controller.
void Start ()
{
control = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update ()
{
distanceTraveled = transform.localPosition.x;
score += Time.deltaTime * 20;
move = new Vector3 (Input.GetAxis("Horizontal"),0f,0f);
move *= playerSpeed;
if(Input.GetKey(KeyCode.LeftArrow))
{
transform.forward = new Vector3(0f, 0f, -1f);
}
if(Input.GetKey(KeyCode.RightArrow))
{
transform.forward = new Vector3(0f, 0f, 1f);
}
if (!control.isGrounded)
{
gravity += Physics.gravity * fallSpeed * Time.deltaTime;
}
else
{
gravity = Vector3.zero;
gravity.y = jumpSpeed;
}
move += gravity;
control.Move(move * Time.deltaTime);
}
Answer by AeonIxion · Dec 11, 2013 at 06:45 PM
http://answers.unity3d.com/questions/8207/charactercontroller-falls-through-or-slips-off-mov.html
The answers there will probably help you with the jittering problem. I'd personally go for Codayus' solution.
As for your character jumping when it hits a platform..At line 35 you're setting the y value of your gravity to the jumpspeed every time the controller (player) is grounded. I think you only want this to happen when the user presses a button?
Thanks ill check it out, the reason it's auto jumping is because it's landing on a trampoline type thing
Your answer
Follow this Question
Related Questions
How to "add force" to a character controller 1 Answer
CharacterController.Move problem with pause menu 2 Answers
hi, how to give controls to a 3d character model. i have downloaded the model as .fbx file 0 Answers
charactercontroller.Move Jump not working! 2 Answers
Character Controller Script Increasing characters Y position 1 Answer