- Home /
resetting rotation on a single axis
I've created a script to rotate the camera on the z axis in order to allow the player to look up and down while holding the arrow keys down. I want to make it so that when they release the key, only the z axis rotation is reset, but the only script I've gotten to come close to working resets all axes, which is disorienting and not at all what I want.
This is the current script to reset rotation upon release of the key:
if (rotatingVertically)
{
if (Input.GetKeyUp(KeyCode.UpArrow))
{
transform.rotation = Quaternion.identity; //resets rotation but resets all axes
rotatingVertically = false;
}
else if (Input.GetKeyUp(KeyCode.DownArrow)) //executes the first frame that the user releases the DownArrow
{
transform.rotation = Quaternion.identity; //resets rotation but resets all axes
rotatingVertically = false;
}
}
Answer by Wolfdog · Jun 10, 2015 at 06:56 PM
This is what I would do:
transform.rotation = Quaternion.Euler(transform.rotation.x, transform.rotation.y, 0);
this produces the same result, and for some reason also prevents me from being able to look down after already looking up
Quaternions are messy, or rather, our understanding of them often is. I recommend reading an ebook on them. Painful to read, but incredibly useful. This Free Ebook From Dartmouth University is an excellent start
Answer by Dave-Carlile · Jun 10, 2015 at 06:57 PM
What Wolfdog said. Or if you know the reset direction, try Quaternion.SetLookRotation.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Align Player to Regional Up Direction, Without Altering Look Direction Dramatically 0 Answers
Trouble with Camera Rotation Math 2 Answers
Weird shake when I try to rotate player according to Virtual Cameras rotation. 0 Answers
How can i rotate a object more than once (90 degrees)? 1 Answer