Day Night cycle? [Solved, see post #5 for how]


Does anyone have any good links or info on how to animate a day night cycle? I think I’m going to do it with two hemi facing opposite directions, and a spot for shadows. But I need a bit of help when it comes to colors and brightness. So could anyone maybe help me?


Depending on how your scene is set up, you could keyframe the “energy” parameter of a lamp, or just its position as it moves across the sky. Given that the sun’s motion is predictable, it might also be possible to fake dynamic shadows by making a “shadow” object and scaling it appropriately as the day goes by.

If you have Ocarina of Time (or possibly Majora’s Mask?), play it, and spend some time (as an adult!) standing around in Hyrule field watching how they do lighting and shadows and stuff, even with very low processing power.

in my program i do this to change the intensity of the light so i can see my scene with a lot of light (day) or without it (night) this is my python script. i hope this help

import GameLogic as g

obj = g.getCurrentScene().objects

 lamp1 = obj["OBLamp"]

if day == 0: = 10
if noon == 1: = 1.5
if night: = 0

Ok well it seems to work alright just by animating it, but I need a bit of help whe it comes to what colors show when, and how long to make the animation. I would like it to be like harvest moon or something, where every second is one minute in the game. So mainly I just need help on setting the color and the energy of the hemi, to make it look good.

Alright I got it working pretty good. In case anyone else wants to know, I made an animation of 144 frames, made daytime last 60 frames, then change to orange over 6 frames, then change to blue over another 6 frames, then stay blue for 60 frames, and finally change back to white over the final 12 frames. Then I set the ipo to chage with a property that adds one every 600 frames. This makes it so that one full day lasts 24 minutes. Or 1 second in real time is 1 minute in game.

Just a little point, you might want to make the sunlight slightly yellow, instead of white, as atmosphere scatters some of the blue light (hence blue sky)

Also, are you going to account for which season it is? (since the length of daylight is different depending on what time of the year it is, also colors are slightly different- and if it’s cold you probably want to make the light blue-er, or visually colder)

Ok ya I could make it a bit yellow, thanks for that. And no I’m not going for seasons, I’m just trying to make it look good.

One other thing I was wondering, is there a way to change the color of lights with python? Cause then i could do it the same way but instead of an animation, I could just change it in python. And then I could also simulate seasons.

import GameLogic as g
I don’t understand, I got an ImportError from Console.
ImportError: No Module named GameLogic

I use Blender 2.49b and Python 2.6

Try replacing the import line with

 g = GameLogic 

In the game engine, whenever a script is loaded up, GameLogic is automatically imported, no need to do it again.

Hello Captain Oblivion,

thanks for your reply… I have tried your suggestion and it also doesn’t work and in return the console that given me the same response:

NameError: name ‘GameLogic’ is not defined

I tried to see if the GameLogic exist inside Blender python library by doing the ‘print’ code line:

print dir(Blender)

and from the list, it also doesn’t even show that it exist the GameLogic…

the version that I am using is 2.49b, does this mean the ‘b’ suffix is beta?
and if that is the case, what other version could I use that I could safely transition my current work without the ‘compatibility’ issue that it will not get accepted because of its recent release?

I’m pretty sure the Blender library is not available in the GE, are you running the script, or the game? (to run the game hit ‘p’ with the mouse over the viewport)

Hello again,
I am glad that you asked that question Captain Oblivion.
When I run the script from text-window (alt+p method) it shows those errors…
However when I try to run from game ‘p’, I would later found out that the intended scripts worked!

so for now, case solved! (I guess, as long I could have the ability to execute code of GameLogic, Rasterizer and its equivalent GE python API)

I would like to see every step that I code in python (trying to make as much use of console and debug overlay) It is just this odd experience that it works in-game and not by running that script in text window.

I would also like to discuss with regard on the relevance of this thread about day/night cycle:

I was making use of this python site:

and I would like to know if there is some activity that the setMistColor(rgb) would be implemented or somehow that these World settings: AmbientColor, Mist, etc… will run at GE for 2.50 or if there exist an alternative build in the works of it?