Character rotation is jittery
I am trying to write a player controller for my character and for the most part it works but I have a problem with stuttering.
In my hierarchy, The camera is separate from the player, and the CameraPivot and GunPivot are attached to the player.
When I rotate on the Y-axis it seems fine, but rotating my character to look up and down (X-axis) makes the movement of the gun, hands and camera stutter or jitter or out of sync.
I Know there are many other topics on this, but I was not able to find anything that works for this. I have tried using LateUpdate, and FixedUpdate(with Fixed deltatime) (Neither seem to help). Also I have tried quaternion or slerp, but unsure of how to actually implement them into my code.
Any help will be appreciated. Thanks.
void Update () {
//Player Move Stuff
Forwards = (Input.GetAxis("Vertical")) * runspeed * Time.deltaTime;
Sideways = (Input.GetAxis("Horizontal")) * sidespeed * Time.deltaTime;
transform.Translate( new Vector3 (Sideways, 0, Forwards));
RotatePlayer = Input.GetAxis ("Mouse X") * TurnSpeed * Time.deltaTime;
transform.Rotate (new Vector3 (0, RotatePlayer, 0)); //Rotates the player
//player Camera Stuff
PlayerCamera.transform.position = new Vector3((CameraPivot.transform.position.x),(CameraPivot.transform.position.y),(CameraPivot.transform.position.z)); //Camera follows the pivot location
RotateCamY += Input.GetAxis ("Mouse X") * TurnSpeed * Time.deltaTime;
RotateCamX += Input.GetAxis ("Mouse Y") * LookUpDownSpeed * Time.deltaTime;
RotateCamX = Mathf.Clamp (RotateCamX, Xmin, Xmax);
Vector3 PivotVector = new Vector3 (-RotateCamX , RotateCamY+180, 0);
PlayerCamera.transform.eulerAngles = PivotVector; //Rotates the camera
CameraPivot.transform.eulerAngles =PivotVector; //Rotates point the camera is attached to
GunPivot.transform.eulerAngles = PivotVector; //Rotates point the gun is attached to
}
Answer by zachwuzhere · Mar 02, 2017 at 02:34 AM
Thanks to all who have helped me thus far, I found out what the problem was.
I rewrote it and now it is smooth as butter!
Your answer
Follow this Question
Related Questions
Any simple ways of keeping track of simple rotation? 2 Answers
Limiting top down rotation amount - 2d 1 Answer
how to get object rotation? 1 Answer
Rotation Issue 0 Answers
Questions about Rotations in unity 1 Answer