Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Time of Day / amount of light

Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
03-06-2006 16:58
Is there any way to detect the amount of ambient light to turn on lights? Or is the only way to approximate based on the time of day as found in the wiki at http://secondlife.com/badgeo/wakka.php?wakka=llGetSunDirection?

Thanks!
Jher Quartermass
Registered User
Join date: 24 Sep 2004
Posts: 18
position of the sun as a variable
03-07-2006 20:51
I've done this before.. In a very simple on/off way, you can do this:

CODE
default {
state_entry() {
llSetTimerEvent(4);
}
timer() {
vector sun = llGetSunDirection();
if(sun.z > 0) {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
llSetPrimitiveParams([PRIM_PHANTOM, TRUE]);
llSetAlpha(0.01, ALL_SIDES);
}
else {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llSetPrimitiveParams([PRIM_PHANTOM, TRUE]);
llSetAlpha(0.20, ALL_SIDES);
}
}
}


If you want more granularity, change the sun.z math. Like so:

CODE
         if ((sun.z > 0.0) && (sun.z < 0.10)) {
play_sound();
}

if ((sun.z > 0.10) && (sun.z < 0.50)) {
setcolors1();
}

if ((sun.z > 0.50) && (sun.z < 0.60)) {
updateParticles1();
llSetColor(<0,0,0>, -1);
}

if ((sun.z > 0.60) && (sun.z < 0.70)) {
updateParticles2();
llSetColor(<0,0,0>, -1);
}


etc... Night time also works, its just negative.

this script looks at the sun or the moon.

CODE
        if ((sun.z > 0.01) && (sun.z < 0.99)) {
llLookAt(llGetPos() + sun,1,0.1);
} else {
llLookAt(llGetPos() - sun,1,0.1);
}