I have been picking at this for a while and still have no idea how or why the player practially summons satan when they look up or down. This is a script for player head rotation and it works as intended except from when the player looks far enough up or down.
I have an object with a rigidbody on it, and a camera inside this object. Quite new to CSharp and object based programming so im a bit slow in the head when it comes to getting my head around this stuff. Im suffering a bit of sunken cost fallacy so I kinda dont want to use another method for looking around.
using UnityEngine;
public class rotationManager : MonoBehaviour
{
private float yaw, pitch;
private Quaternion playerRotationX, headRotationY;
//parent object to the camera
[SerializeField] private Transform Player;
//the camera
[SerializeField] private Transform Head;
void Update()
{
// float keeps track of the rotation of the head
yaw += Input.GetAxis("Mouse X");
pitch += Input.GetAxis("Mouse Y");
// set two quaternions for each rotation
playerRotationX = Quaternion.AngleAxis(yaw, Player.up);
headRotationY = Quaternion.AngleAxis(-pitch, Head.right);
// set the rotation of the player body and player head
// multyiply the X rotation of the player as Camera x moves independantly
Player.rotation = playerRotationX;
Head.rotation = headRotationY * playerRotationX;
Debug.Log(headRotationY.eulerAngles + " : " + playerRotationX.eulerAngles);
}
}