- Home /
check x axis rotation,limit objects rotation
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.
Answer by uni-TT · Jan 15, 2020 at 05:23 AM
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;
}
if you want to limit the rotatio maybe something like mathf.clamp if not that i don't really understand your question
Your answer
Follow this Question
Related Questions
Rotating a model with increments 1 Answer
Multiple Cars not working 1 Answer
How to set a single-axis rotation and not change the others axes 1 Answer
Distribute terrain in zones 3 Answers