I want to limit the x axis of rotation to 90 and -90, but to do this i need to somehow read the current x rotation. Thought that would be simple but when using Transform.localEulerAngle i get values around 360 when in the inspector it says 0. and just reading the Transform.rotation.x gave me a quaternion which i googled and after reading “4th dimensional”, promptly gave up on. Any help or advice?
Ok, ive done some research and i couldn’t find anything helpful. If you are manually moving the rotation in code like me you can make a float and change that by the same angle you change the rotation, Probbably wont work for more than 360 degree rotations.
Probbably should’ve had this in the main post. Nonetheless here’s the scripting i mashed together to get it to work. (note, i didnt copy paste the whole thing because its massive, long story short “manualangle” is the float i use to check the x rotation and “camrot” is the amount i want to rotate it. Rest is self explanatory)
//moves the camera
player.MoveRotation(player.rotation * Quaternion.Euler (rbRot));
camera.Rotate (camRot);
//the float with the "fake" angle
manualangle += camRot.x;
if (manualangle > 90f){
camera.localEulerAngles = new Vector3(90f, 0f, 0f);
manualangle = 90f;
}
if (manualangle < -90f){
camera.localEulerAngles = new Vector3(-90f, 0f, 0f);
manualangle = -90f;
}