No idea how to use Euler angles...

Euler angles aren’t as straightforward to me as it is for you smart people. I’ve watched a lot of videos about it, and I understand how it works, but I can’t find any videos explaining how the numbers behave. So with the following code, I’ve got a behavior show in the video:

var rotationX : int;

function Update() {
	transform.eulerAngles.x = rotationX;
}

How am I supposed to get it past 90 degrees without it glitching like that?

The problem with using rotation based on the X axis is that it will actually change the value of Z in the transform’s euler angle and reverse the X-axis. You will notice it if you switch to the rotate tool and rotate the object on the X axis. This is I believe to actually prevent Gimbal Lock (I hope someone can come along and clarify this!).

One easy way which I use to bypass that is to parent it to another game object and rotate it such that rotating the parent via the Y axis will rotate the child the way I want (as rotating Y will give you the full 0-360). Another way is that you can check the Z axis and reverse the value of your X for euler angles.

Also, euler angles is the displayed rotation value on the inspector. In case you didn’t know.

Use RotateAround Unity - Scripting API: Transform.RotateAround

    var rotationX : int;
     
    function Update() {
        transform.RotateAround(Vector3.zero, Vector3.up, rotationX);
    }

Trouble is that this makes it constantly move. I don’t want it to move in that fashion, I basically want to tell it “your angle of rotation = this number / 240”.

It needs to rotate to a particular angle that equal the second of the day divided by 240, so as to create a real-time rotation.

If there are 86400 seconds in a day, I want to divide the second of the day by 240 to get the appropriate angle that the Sun needs to be at. Not sure if any of that makes sense.

Well, let’s modify a little bit this code and it will work as you need, I think :slight_smile:

        var rotationX : float = 0;

        @HideInInspector
        var last_rotationX : float = 0;
         
        function Update() {

            if(rotationX != last_rotationX)
            {
                transform.RotateAround(Vector3.zero, Vector3.up, rotationX - last_rotationX);
                last_rotationX = rotationX;
            }

        }

This is brilliant. You were my hero for the day.

Also, your live tiles are awesome. If I had the money, I’d throw it at you immediately, even if I currently have no use for it. But alas, I was lucky to get the cash to get Pro @__@

I had to modify the code a bit, because I need Rotate, not RotateAround, but the math remains, and implementing the real-time functionality was very very simple.

var rotationX : float = 0;

@HideInInspector
var last_rotationX : float = 0;

function Update() {
	rotationX = Timekeeper.secondOfDay / 240;
	if(rotationX != last_rotationX)
		{
			transform.Rotate(rotationX - last_rotationX, 0, 0);
			last_rotationX = rotationX;
		}
}