Hello
I am a beginer in Unity so please be Patient.
I am trying to rotate a plane upto 30 degrees in each direction using Vector3.up ,.down,.left and .right.
My z local Rotation Needs to be Zero all the time.
I tried to Limit the Rotation using clamping but does not seem to work.
It rotate over 30 degrees all the time.
I require some help so as to Limit my Rotation in each direction.
this is my code:
void Update ()
{
Vector3 mirrorRotation = mirror.transform.localRotation.eulerAngles;
mirrorRotation.z = 0;
mirror.transform.rotation = Quaternion.Euler (mirrorRotation);
Angle = mirror.transform.eulerAngles - originMirror;
Debug.Log ("Angle:" + (mirror.transform.eulerAngles - originMirror));
if (thumbTipPosition.x >= originThumb.x) {
mirror.transform.Rotate (Vector3.down * RotationSpeed);
Debug.Log ("rotatedRight");
} else if (thumbTipPosition.x <= originThumb.x) {
mirror.transform.Rotate (Vector3.up * RotationSpeed);
Debug.Log ("rotatedLeft");
}
if (thumbTipPosition.y >= originThumb.y) {
mirror.transform.Rotate (Vector3.right * RotationSpeed);
Debug.Log ("rotatedUp");
} else if (thumbTipPosition.y <= originThumb.y) {
mirror.transform.Rotate (Vector3.left * RotationSpeed);
Debug.Log ("rotatedDown");
}
clampedXValue = Mathf.Clamp (mirrorXvalue, -maxRotation, maxRotation);
Debug.Log ("clampedX" + clampedXValue);
clampedYValue = Mathf.Clamp (mirrorYvalue, -maxRotation, maxRotation);
Debug.Log ("ClampedY" + clampedYValue);
}
//
// void ClampAngleX()
// {
// if (mirrorXvalue > 30) {
// mirrorXvalue -= -0;
// }
// else if (mirrorXvalue < -30) {
// mirrorXvalue += 30;
// }
//
// mirrorXvalue = Mathf.Clamp (mirrorXvalue,-maxRotation,maxRotation);
// Debug.Log (“Xvalue:” + mirrorXvalue);
// }
}
Thank aton