I need to store my objects world rotation from the inspector as a variable to use in a function, but there’s something wrong with my code I don’t understand. I create a float variable, and tell it to be equal to the current objects Y rotation in the update function, but instead of storing the actual value (a value between 0.0 and 360.0) it comes up as some number between 0.0 and 1.0. It doesn’t even appear to be proportionate to the actual rotation because multiplying it by 360 doesn’t give the same value. What am I doing wrong?
You should probably show some code in [co****de] blocks here, so we can see what’s wrong.
A quaternion is not a set of angles. It’s a hypercomplex number (w + **xi * **yj + **z***k), and you can’t really make use of the four component numbers individually in any meaningful way. Think of it as one value all together. Modifying just one element will almost surely make for crazy behavior.
The gameObject has a transform component. The transform component stores the local position (a vector3) and orientation (a quaternion). The Transform class also has helper conversions to give you the Euler rotation as angles in degrees around Z, X, Y axes in that order. Since Y is the last axis, and since it’s a conversion from the quaternion, and since it’s local coordinates, you may run into some gimbal lock problems and inconsistent behavior. Storing just the Y rotation in a variable may get a bit complicated. Consider saving a Quaternion variable with the whole world rotation or localRotation instead.
I don’t really understand Quaternion variables, is this what you’re suggesting I do?
C:\Program Files (x86)\Unity\Editor\Data\Documentation\Documentation\ScriptReference\Quaternion-eulerAngles.html
You Could Try ArrayPrefs2. Its A Very Nice Extension That Allows You To Save Things Like Colors And Vectors. Im Guessing That Means You Could Also Save Rotation.