Can't edit an object's rotation manually?
I am writing a script which will allow the player to rotate the camera around an object. However, I can't seem to force the camera's x rotation to stay between +90 and -90 (270) degrees. AFAIK the code below should work, but it doesn't and I don't know why...
if (transform.eulerAngles.x >= 89 & transform.eulerAngles.x <= 270) {
Vector3 temp = transform.eulerAngles;
print ("stored in variable");
temp.x = 88.99f;
transform.eulerAngles = temp;
print ("Completed, x = " + transform.eulerAngles.x);
}
AFAIK, using this, if the camera gets too close to equaling a 180 degree rotation on the y and z axis the code should just move the camera position back. It does, if the camera movement is slow enough, but I'm using mouse input and the mouse speed adjusts the rate of the camera rotating.
Does anyone know of a workaround?
Answer by Edmonds · Jul 13, 2016 at 10:07 PM
No worries! I found a solution! (verticalAdd is the sum of the camera's current X angle and the vertical movement of the mouse)
if ((verticalAdd >= 87 & verticalAdd <= 273) & vertical > 0) {
Vector3 temp_high = transform.eulerAngles;
temp_high.x = 87.0f;
transform.eulerAngles = temp_high;
} else if ((verticalAdd < 273 & verticalAdd > 87) & vertical < 0) {
Vector3 temp_low = transform.eulerAngles;
temp_low.x = 273.0f;
transform.eulerAngles = temp_low;
} else {
transform.Rotate (vertical, 0, 0);
}
Your answer
Follow this Question
Related Questions
Calculating the Hit Point on a Sphere (with Rotation, Based on Static Nodes) 0 Answers
Rotation Lerp Question 2 Answers
[VR][VIVE] allow rotation only ? 4 Answers
Rotation problem: Object rotates but shouldn't 0 Answers
rotating camera jumping around y axis? 0 Answers