I know that this is a vage question, but how do day night cycles work in video games? How do I get started programming one? I have researched for a while, but the only thing I saw was "unity 3-d day night cycle". I need just a basic concept.

Edit: I mean how to make it appear visually. I'm sorry for not saying that first.

  • 1
    \$\begingroup\$ You should probably ask how to show them visually in a separate question, since you've now basically asked something completely different. :) \$\endgroup\$ Oct 15, 2012 at 4:01
  • \$\begingroup\$ Perhaps this question is related to your needs. \$\endgroup\$
    – user1430
    Oct 16, 2012 at 16:09

3 Answers 3


This will depend a lot on what you want to acomplish and the type of game you have.

You would have a 'game world' time that advances based on the cpu clock. Generally at a much faster pace so it can be seen. And you will need to take into account pausing, alt-tabbing and so on. You can also advance it manually such as when the player sleeps, uses some kind of fast travel system (a less simple one would be based on the distance travelled) or from mission to mission. More complex game time keeping systems might keep a record of the date and potentially even have their own calendar systems (Like the Elder Scrolls series). This could influence weather and so on.

You need to adjust your visuals based on the game time. This normally involves lighting and the sky. For a simple system, outside will normally have a light that represents the sun. You would need to adjust the brightness/color based on the time of the day and set it to a much darker color at night. And the sky texture itself will need to switch between day, night and dawn/dusk textures (preferably with some kind of smooth fade).

More advanced visual systems will track a path for the sun and moon across the sky. A simpler system many just put them at polar opposites to each other and have them go directly overhead, east to west.

In reality both bodies have their own paths. The moon can be up during the day at the same time the sun is. The moon has cycles. And both will often not be directly over head but on an arc the angle of which changes depending on the time of the year. The stars them selves will change slightly too.

Skyrim was even more advanced and had 3 moons. The original Theif games actually had star charts rather than just using a texture.

You will also want to use the suns position for shadows is you have realtime ones.

  • 1
    \$\begingroup\$ Thank you for the answer. I like the idea of multiple moons! Sorry I can't rate up yet. \$\endgroup\$ Oct 15, 2012 at 2:43
  • 1
    \$\begingroup\$ +1 for taking most of the aspects into account, and the detailed explanation. \$\endgroup\$ Oct 15, 2012 at 16:20

The reason you're not finding anything is probably because it's so exceedingly simple there's nothing to ask about and nothing much to talk about.

Here's how a day/night cycle works:

  • You have a sun and moon that travel overhead (maybe also stars, etc).
  • Your game has a time of day.
  • The position of the sun and moon, and appearance of the sky, depends on the time of day.
  • The lighting conditions also depend on the time of day.
  • There might be mechanics to let you skip a certain number of hours ahead: you can wait/rest until a given time of day in The Witcher 2, and Minecraft has beds which let you sleep til dawn.

That's it. That's all there is to it. Whatever else you want to do is up to you.


They work just like day/night cycles in real life. It's daylight for a specific amount of time, then it's dark for a specific amount of time.

Basically you have an elapsed time counter. You decide how much real world time converts to your game time day.

This is typically displayed through the skybox and lighting. Display a sun and blue sky during the day, show starts and the moon at night.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .