Rotation fails to work correctly when the rotation of another object goes past a cetain point.
I'm having a bit of trouble with my code. It seems when I rotate my character passed a certain point (seems exacerbated when rotation flips between positive and negative), my vertical mouse inputs are flipped or seemingly flipped where the character head rotates up when i move the mouse down and vice versa. Everything is working as expected when I first start. Its also interesting that when I continuously rotate my character horizontally, the head rotates vertically as if it was following a sin wave. void Update() { UpdateCharacterMove(); UpdateCharacterLook(); }
public void GetCharacterMove(Vector2 moveInput)
{
moveInput.Normalize();
characterMove = new Vector3(moveInput.x, 0, moveInput.y);
}
private void UpdateCharacterMove()
{
Vector3 velocity = transform.forward * characterMove.z + transform.right * characterMove.x;
velocity *= moveSpeed * Time.deltaTime;
controller.Move(velocity);
}
public void GetCharacterLook(Vector2 lookInput)
{
characterLook = new Vector3(lookInput.x, lookInput.y, 0);
characterLook.Normalize();
Debug.Log($"{characterLook}");
}
private void UpdateCharacterLook()
{
cameraPitch -= characterLook.y * mouseSensativity;
cameraPitch = Mathf.Clamp(cameraPitch, minCameraPitch, maxCameraPitch);
Vector3 zAxisCorrection = transform.right * cameraPitch;
zAxisCorrection.z = 0;
head.transform.localEulerAngles = zAxisCorrection;
transform.Rotate(characterLook.x * mouseSensativity * transform.up);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613060510im_/https://answers.unity.com/themes/thub/images/avi.jpg)