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.
// 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
}
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.