http://jerome.le.chat.free.fr

Home > Blender > Scripts > Sun Engine - change the sun revolution speed during the game

Sun Engine - change the sun revolution speed during the game

Article Index
Sun Engine
latitude and longitude
configure date and time
sun revolution speed
advanced
change the sun revolution speed during the game
display the current date and time in the game
script integration
sun position mecanism alternative
sun objects and properties reference

to interact with the sun animation, you can act on the following properties. they don't need to be created by hand : for the following setup I've configured the following properties :

 

usefull properties :


  • startSecs (type:string). the starting date in seconds since epoch. update this value will update the sun position, keeping the current speed and time offset. if omitted, the local time will be used.
  • timeSecs (type:string). is the current active time in seconds since epoch. let the script create this value ; then you can add a time offset in seconds once the game is running.
  • sunspeed (type:int). offset in seconds. value is 120 if the property does not exist (omitted)
    . if 0, it will stop the sun,
    . if > 0, it the time will increase,
    . if < 0, it will decrease.
  • realsunspeed (type:Bool) False if omitted
    . True : use the 'true' time for animation
    . if True and sunspeed = 0, the sun will stop
    . False : use the sunspeed value.
  • sunrestart (type:Bool) False if omitted
    . True tells the script to restart the animation from the configured time or the local time,
    . the script will toggle the value to False by itself.
  • uselocaltime (type:Bool) - True if omitted and no time configured
    . True : use the local time,
    . False : use the time configured in the properties.
    . if uselocaltime and sunrestart are True, the current time will be used as starting time.
    . local time is always available, just set this property to True.
  • sundist (type:Float) - 10 if omitted
    . a multiplicator used for the sun-earth distance.
  • uselocalstring (type:Bool) - False if omitted
    . language used for month and day strings, see next page.
    . True : local date strings,
    . False : use your own strings.
  • sundebug (type:Bool) - True if omitted
    . True : displays time in console
    . False : displays nothing
  • suninit (type:Bool) - False at init
    . False tells the script to re-initialize (parse the whole configuration again and restart),
    . True for normal operations. the script will toggle the value by itself.

you can also prevent the script to run thanks to a boolean : see delay the script execution below.

let's add some keyboard controls :

  • select your sun object, then in the logic panel :
  • create all the actuators on the right :
  • create an AND controller for each of them,
  • link each controller to one actuator.
  • add a keyboard sensor, call it pageup, clic on the key field and press the pageup key
    enable TRUE level triggering and link it to increase
  • do the same for the pagedown key and decrease
  • from now, don't enable TRUE level triggering
  • do the same for the space key and stop,
  • do the same for the end key and realspeed,
  • home and restart
  • del and localtime
  • L key and language
  • pad 1 key and 2000 and timezone
  • pad 2 key and 1972 and timezoneB
  • pad 3 key and 2099 and timezoneB
  • run the G.E.


The following controls are now available :

 

pageup : increase sun revolution speed
pagedown : decrease sun revolution speed
end : switch between true sun speed and pageup/down controls
del : switch between localtime and configured time
space : pause time
home : init time offset (back to the current start time)
1,2,3 : predefined dates (see last actuators)
L : use a non-local language (see next section)

 

when switching from a time to another one, the current speed (or paused status) and the offset are the same. the time interval between the times remains the same whatever the speed status is.

you can't directly add a value to startSecs or timeSecs with logic -you can only assign a new value, since it's a string. I know it looks odd but one can't use floats or integers greater than 10000 or lesser than -10000 in the properties, and this interval irepresents less than 6 hours in seconds.
you have to convert first to float or int, update, then convert back to string, with something like :

 # add one day
config['startSecs']=str( float( config['startSecs'] )+86400 )
# add on day, but preserve the time offset with the other dates.
config['timesecs']=str( float( config['timesecs'] )+86400 )

 



Last Updated on Friday, 23 October 2009 14:20