Create a clock from an actor rotator

Hi all,

I’m trying to create a day night system where NPC will react depending of the time (like go to bed during night).

I have the light cycle by rotating the Light Source by “AddActorRotation”.

Now I found on the net a lot of tuto to caculate the clock just by adding values to the seconds but sometimes if you pick a slow “day speed” for the rotation, the hours are delayed from the light cycle resulting in inaccurate calculation.

So I would like to get the minutes of the day from the rotator of the light actor. Unfortunately it’s not just a 0->360 rotation. It’s more like 0->90->0->-90 or something like this resulting in something ugly that I can get to work.

I just want to get the time of day depending to the rotation of the light so that it’s more accurate. Is there a solution here?

Or do you have a better solution for an ingame clock?

Thank you in advance

Hey there @JikaiNoTsubasa! Welcome to the community!

So technically there’s many ways to make a clock, and it’s usually best to define the rotations by the clock and not the other way around, but in reality it doesn’t matter too much. Your implementation is perfectly fine! All you need is one little node and you can make the rotators read out 0 - 360!

The clamp axis node makes rotator readouts between 0 and 360 instead of -180 and 180.

UnrealEditor_2022-11-07_03-45-53

This should allow you to just continue work on your system, let me know if you have any questions!

Thank you for your fast answer.

I have a strange behaviour when using your solution.
Here is my case:

But I have these results:
0->90->0 then it jumps to 360->270->360 …

I don’t have a straight 0->360.
I use the Y axis maybe that’s why?

Oh wow I see! You’re correct, it seems the Y axis functions entirely differently than the X axis. Looks like it’s ping ponging after going +90. That’s a feature I didn’t know of! I might have to show you a different solution in this case.

The other solution is to keep a variable like a rotation log in that whenever you increment the rotation you increment this variable by the same amount. This way it’s locked to your rotation, but it does mean that if you have to set the time manually you need to do it to both, so it’s recommended to use functions for that portion.

I don’t like the fact the 2 are not connected (time and rotation) by adding the same value to the time aside of the rotation but it seems to work better than the solution I had before.

I tried to slow down the speed to a more realistic cycle but then the rotation of the light stops when it hits perfect 90 or -90…

Is there a problem with the addRotation?

[EDIT]
I found this about this problem:

It’s called Gimbal Lock…

[EDIT 2]
I’m trying to get rid of the Gimbal Lock issue.
Also I found the node “rotator from axis and angle” which should do exactly what I want. It works fine until angle 90° then it goes crazy in every directions…


Here the “New Rotation” output is the angle 0->360 incremented each frames.
The Clock node just does the Angle to Hours convertion and stores it.

So I fixed it by using the plugin “Sun Position Calculator” as you just have to provide it your time in hours/mins/secs days etc and it calculates the position depending of the logitude and latitude you give it.

I wanted an accurate sun cycle with hours, here it is!
Here’s how I did it, so simple…


The SunPosition is just a REF on the plugin Sun Position BP put in the scene. It will connect to the light source and sky sphere autoatically.

1 Like