Day / Night Cycle – Change on Key Press

As a progression from the real-time day / night cycle I created previously, I wanted to simplify this down into a choice of the player, whether it be a key press or through an additional widget such as a slider.

I found a great tutorial on how to implement this through a key press of your choice, switching from day to night when you wish.  The method I used also includes text which overlays the screen telling the player whether it is day or night.

DayNightKeyPress2 DayNightKeyPress3

The way in which it works is that I have set the sun directly above the scene and on the key press, this rotates 180 degrees on the y axis, changing the sky sphere with it.


There is an extra inclusion of a “night threshold” variable, which allows the creator to choose a point on the rotation it is considered to be night or day. Also, creating an event for each (“Become Day” and “Become Night”).  These custom events allowed me to add options to when either of these events occurred, in this case, display text informing the player.

I had a problem where the sun was still casting shadows from below the horizon, when it should be night.  To counter-act this, I included extra code which had the sun intensity at 2.75 when its was considered “day time”. Finally, setting the intensity to 0 when it was “night time”, which solved the problem.

I still however, want to add a secondary light source in the Moon.  I wish to add this to the sky sphere, casting shadows and light equivalent to the sun, albeit with less intensity.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s