I want my character to walk around sphere like a planet, so in my script I rotate it according to the normal of a raycast and I also rotate my character on the Y axis when I look around with the mouse. When press play, I can look in any direction in front of me, left and right, but when my characters Y rotation gets closer to 180, the X and Z rotation start jittering.
RaycastHit hit;
Vector3 rayStart = new Vector3(0,-1,0) + transform.position;
if (Physics.Raycast(rayStart, -transform.up, out hit, Mathf.Infinity))
{
Vector3 rotation = new Vector3(Quaternion.LookRotation(hit.normal).x,0, Quaternion.LookRotation(hit.normal).z);
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
transform.eulerAngles = new Vector3(rotation.x,transform.eulerAngles.y,rotation.z);
}
I also tried transform.rotation = Quaternion.Euler(rotation.x,transform.eulerAngles.y,rotation.z);
but it changes nothing. If I remove the 3rd line, it works, so i'm guessing i'm assigning the rotation the wrong way ?
Both the line to rotate the character according to the camera and the one to rotate it around the planet work individually, but not together.