- Home /
Float value = gameobject.rotation
I was trying to find answer for that question, but I can't. I want to make a balance scene in which when your rotation = 15 or -15 you fall, but i dont know how to assign rotation value to float. I tried with quaternion, but it wasn't working. I only want to know how to assign float to rotation.
Answer by unit_nick · Sep 05, 2017 at 06:27 PM
// assuming z is forwards you would rotate +/- 15 on z axis
float tippingAngle = 15;
// get a relative angle with range +/- instead of 0 - 360;
float relativeAngle = ((transform.rotation.eulerAngles.z + 540) % 360) -180;
if (Mathf.Abs(relativeAngle) >= tippingAngle)
{
// fall
}
Answer by Glurth · Sep 05, 2017 at 06:27 PM
In 3d space one can rotate in lots of ways. When I nod my head in rotates one way, but when I shake my head, it rotates a different way. The difference specifically, is, the "AXIS" around which my head is rotating. If I turn my head down and to the right, is it rotated around BOTH of those axis. In 3d space, one can define a rotation as 3 rotation angles around the three spaial axis (X, Y, Z). This format is known as "EULER angles".
I suspect you want to use ONE of the rotation's euler angles (though I've no idea WHICH one). e.g.
float rotAboutY = transform.eulerAngles.rotation.y; // this gets the rotataion around the Y axis, in degrees.
Your answer
![](https://koobas.hobune.stream/wayback/20220612134247im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Flip over an object (smooth transition) 3 Answers
Camera rotation stop if x is 50 2 Answers