Blender Game Engine/ How to move the Sun using the “Time-Property”?

Blender Game Engine/ How to move the Sun using the “Time-Property”?
QUESTION LEVEL: beginner
BLENDER Version: 2.69.0

I managed to move the SUN-Lamp using the Property Time in the normal object mode. The script looks like:

import bpy
#bpy.context.space_data.context = ‘WORLD’
bpy.context.scene.SunPos_property.Time += 1
print(bpy.context.scene.SunPos_property.Time)

Basically the time will be advanced by one hour. The shadows are moving through the day as expected and no errors in the script are occurring;

Basically I saved this script as sunInc.py and assigned it in the logic bricks to the letter “H”

Problem:
After I start the game and press “H” the Sun (and the shadows) does not move.
After I quit the game, I do recognise that the “Time” was increased and the sun position gets recalculated.

Question:
Which function call would cause the game engine to update during the game the sun- and shadow positions?

/uploads/default/original/4X/7/a/6/7a6be7869646a2cdd84599e7f3f3096d0c9bbdee.pngd=1326444037

You can play an action via ActionActuator in property mode. The actuator will set the animation pose according to the value of the given property (Property-field). Be aware it must be a game property (not a Blender property).

Hi,

I tried to migrate the script to bge, but came no so far …

The script looks now like:

import bge

 scene = bge.logic.getCurrentScene()
 t= scene.SunPos_property.Time  
 print(t)

In the Console I get the respond:

Attribute Error: KX_Scene object has no atribute “SunPos_property”

The question now is how to find where this particular property was inserted into the bge data model?
Do anybody has an idea?

Why do you expect the scene to have the property “SunPos_property”?
You have to make it, or better yet, have the light have that property.

Try something like this:


import bge

scene = bge.logic.getCurrentScene()
light =scene.objects['light']
if 'time' not in light:
    light['time'] = 0
else:
    time += 1
    print(time)

i havent heard this before now and maybe im misunderstanding, but isnt the time property just a timer…are you tring to use the time module?

I’ve never try to rotate the sun with the timer property, I think you can try to rotate it every frame with Always sensor


day = 60*60*60*60*24 # only approximation but probably wrong math anyway
angle_per_frame = 360/day
sun.applyRotation(angle_per_frame,True)

Hi,

Background (what I actually try to do):
the point is that I would like to use the astronomic correct positioning of the sun, so that I can simulate how design changes of a house will affect the shadows on the interior walls. Other usecase would be to find an optimal spot in the adjacent garden to plant tomatos etc.

I am using the AddOn: Sun Position (http://www.blendernation.com/2012/12/30/add-on-sun-position/)

In Modelling Mode:
it runs as expected… After activation of the addon in user preferences under Menu World a new sub menu appears: “Sun Position”. Here I can specify the geographical position of my scene and also set year, month , day, hour and minute. So I can simulate a “real-world-sun”.

In the BLENDER render/3Dview/ change mode to rendered has the nice effect that the changes in the day, time etc are applied in real time to the view.

That is OK, however changing the values in the small input boxes is not so comfortable.

BGE Variant:
So I had the idea to create a game, where hitting the letter M would increase the month by 1, hitting d would increase the day by 1 and so on.

In parallel the Player could move through the scene and inspect the building and the corresponding shadows from any side and to any possible Time point of time.

On that I am stack at the moment…