- Home /
Rotation is reading wrong when I rotate past +/- 90 degrees
I am having problems setting the rotation of an object. I am trying to get it to snap to a dial angle (basically a 10 digit dial) I let the user move the dial to any angle they want then have it snap to the closets whole number setting.
Problem: it works perfectly for one half of the cylinder. moving the dial past the +/- 90 degree mark starts returning transform.localEulerAngles.x from the current side. Rotating the object (-1 degree give you 359 and rotating the object 179 gives you 359)
Here is the code:
public class NumberClicks : MonoBehaviour {
public void snap_to (GameObject pickedObject)
{
var CurrentRot = transform.localEulerAngles.x;
print ("Current Rotation = " + CurrentRot);
var DialSetting = Mathf.Round (CurrentRot / 36);
print ("Rounding to Tenth = " + DialSetting);
var RoundedRot = (DialSetting * 36);
print ("Rounded Rotation = " + RoundedRot);
pickedObject.transform.localRotation = Quaternion.Euler (RoundedRot, 180, 270);
}
}
UPDATE: Further research shows me that I am a victom of the Gimbal Effect when I convert the Quatrain to Euler Angles. Doesn't, however, help me figure out how to get solid solution for my issue.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613200418im_/https://answers.unity.com/themes/thub/images/avi.jpg)