- Home /
Rotation too complicated
I'm trying to make my camera rotate based on Input.GetAxis("Horizontal") and changing this into a Vector3, but it looks like transform.rotate requires a "quaternion." I tried setting the rotation to new quaternion(Input.GetAxis("Horizontal"), 0.0f, 0.0f, 0.0f), but that just made everything go crazy! Can someone please explain how to better apply this code or redirect me to somewhere where I can learn more about it? Thank you.
Answer by Nodgez · Feb 06, 2014 at 06:14 PM
I think what you need there is the Quaternion.Euler function
float angle;
void Update () {
angle += Input.GetAxis("Horizontal");
transform.rotation = Quaternion.Euler(0,0,angle);
}
This lets you set the rotation of your object using a Vector3.
If you want to lock the rotation after certain amount you could implement something like this:
float angle;
float rotationLimit = -1.0f;
void Update () {
angle = Input.GetAxis("Horizontal");
transform.rotation = Quaternion.Euler(new Vector3(0,0,angle * Mathf.Rad2Deg) * rotationLimit);
}
Answer by KurtGokhan · Feb 06, 2014 at 06:14 PM
Quaternions don't work that way. Also transform.Rotate() accepts Vector3 or 3 floats as parameter. Transform.Rotate() You can basically set your rotation like:
transform.Rotate(Input.GetAxis("Horizontal"),0,0);
Answer by John_Sherer · Feb 07, 2014 at 03:11 PM
Yup, I used the transform.Rotate and it worked just fine! Thanks a lot.
You dont have to write a new answer. Accept my answer and if you have something to say, click add new comment.
Your answer
Follow this Question
Related Questions
Lerp Rotation broken 1 Answer
Jittering effect when moving character and camera 2 Answers
how can a camera zoom into a game object? 3 Answers
fixed rotation around object 1 Answer
How does one use quaternion.euler(x,y,z) to rotate on y axis? 2 Answers