Problems With .rotate behavior
Hey, I'm trying to make a day & night cycle. In order to do this I used .rotate.x. The problem is that the rotation goes from 0 to 90, then it starts decreasing to 0. Then It goes from 360 to 270 and then back to 360 and 0. It rotates as I want but to program is very complex. If there is a way to rotate from 0 to 360 and then 0 again it will be much easier to program. It is possible to do this?
Code: sun.transform.rotate = new Vector3(secs,0,0);
Answer by JedBeryll · May 15, 2016 at 06:13 PM
transform.rotation is a Quaternion. It won't work the way you would expect if you assign Vector3-s to it. If you want to rotate it like that you have a few options though:
transform.Rotate(new Vector3(secs,0,0));
// or
transform.eulerAngles = new Vector3(secs,0,0);
// or
transform.rotation = Quaternion.Euler(new Vector3(secs,0,0));
Another option is:
transform.rotation = Quaternion.AngleAxis(secs, Vector3.right);
This will ensure that, rather than using the indirect inputs of Euler Angles into a Quaternion-based system (which then converts values back into the more-commonly-understood Euler Angles), you're constructing rotations directly around Quaternions ins$$anonymous$$d.
Your answer
Follow this Question
Related Questions
How to put limit for Transform.rotate in unity 2d 1 Answer
Simple Rotate Script won't work! 2 Answers
Cant stop object/ridgidbody from rotating 2 Answers
Rotate object with 90 degrees? 1 Answer