- Home /
Quaternions acting up
For some reason the quaternions in the left and right if statments aren't working properly. The object is supposed to move to the left and right, but it just turns down to 180 degrees.
if(Input.GetKeyDown(KeyCode.UpArrow) && SwordReset == 0){
Sword.transform.rotation = new Quaternion(0, 0, 0, 0);
SwingTime = STLength;
}
if(Input.GetKeyDown(KeyCode.DownArrow) && SwordReset == 0){
Sword.transform.rotation = new Quaternion(0, 0, 180, 0);
SwingTime = STLength;
}
if(Input.GetKeyDown(KeyCode.LeftArrow) && SwordReset == 0){
Sword.transform.rotation = new Quaternion(0, 0, 90, 0); //The first issue
SwingTime = STLength;
}
if(Input.GetKeyDown(KeyCode.RightArrow) && SwordReset == 0){
Sword.transform.rotation = new Quaternion(0, 0, 270, 0); //The second issue
SwingTime = STLength;
}
Answer by TreyH · Mar 13, 2018 at 03:10 PM
I think you're confusing Quaternions and Euler Angles.
This might be what you really want:
Sword.transform.rotation = Quaternion.Euler(0, 0, 270);
Right, this numberphile video is one of the best, simplest and most straight forward explainations of how a quaternion roughly works. Quaternions have many advantages when compared to euler angles. While euler angles represent 3 seperate rotations around different axes executed in a particular order, one after another, Quaternions can represent an arbitrary rotation as one single operation. While eulerangles may suffer from things like gimbal lock due to the seperate rotations, quaternion do not have this problem. This is one of the main reasons we use them. They simplify combining several rotations into a single rotation.
Your answer
Follow this Question
Related Questions
(c#) NPC rotator 1 Answer
How i can equal 2 Tranform Rotations? 1 Answer
Rotating a certain axis offsets the other ones? 1 Answer
Flip over an object (smooth transition) 3 Answers
Auto leveling help 0 Answers