Rotation does not seem to make sense
I have an empty gameobject which is in front of the player (so wherever he moves, the gameobject is dead ahead).
There are tumbling cubes falling downwards from the sky, towards the player.
These cubes are spinning at random speeds on the x, y, and z rotation.
When they are caught by the empty gameobject (let's call it "catcher"), I need to set the falling cube that gets caught rotation to 0.
So, in JavaScript/UnityScript I thought it would simply be: Caughtcube.transform.Rotation.x = 0; ... And the same for the y and z axis.
Thing is, this always gives different results depending on the rotation of the falling cube, because the falling cube's rotation is random. I thought setting these values to 0 would work. It does in the inspector, but I need it done at runtime dynamically in script.
Any help greatly appreciated.
Answer by OncaLupe · Dec 18, 2015 at 02:50 AM
Rotations are handled in game as what's called a Quaternion. Quaternions have 4 elements (x, y, z, w), however they do not correspond to the 3-axis rotation shown in the inspector (called Euler). Quaternions are used because they avoid gimbol lock, which is where an object gets stuck on one axis, however they are not easily understood by humans. Luckly there are some methods to convert between Quaternions and Euler.
To set an object to a specific 3-axis rotation, use rotation = Quaternion.Euler(x, y, z)
. Or to easily set to no rotation as you want, there's rotation = Quaterion.identity
. Quaternion.identitiy is a constant for no rotation (equivalent to Quaternion.Euler(Vector3.zero)
)
Your answer
Follow this Question
Related Questions
Get angle of rotation around local axis 1 Answer
Rotate camera upward. 0 Answers
Scaling animation that takes rotation into account 0 Answers
move object in a certain direction 0 Answers