vector llGetSunDirection()
Returns a
normalized vector that points toward the sun's current
position (and angle of the
sim's directional
light source). This vector is updated once every 10 seconds.
The moon is directly opposite the sun at all times, so the negation of the vector returned by this
function points towards the moon. (This implies that the moon is always full in
SL,
which is rather strange, but given the orbital oddities below, this is fairly ignorable.)
A
Second Life day is 4 Earth hours long. 0:00 is midnight and 2:00 is high noon. Sunrise is at approximately 0:30 and sunset around 3:30, which results in 3 hours of daylight and only 1 hour of night-time. Refer to the chart below for approximate
PST and
GMT times. There is no guarantee this data is accurate:
| Phase | PST | GMT |
| Sunset | 2:30 AM | 10:30 |
| Midnight | 3:00 AM | 11:00 |
| Sunrise | 3:30 AM | 11:30 |
| Sunset | 6:30 AM | 14:30 |
| Midnight | 7:00 AM | 15:00 |
| Sunrise | 7:30 AM | 15:30 |
| Sunset | 10:30 AM | 18:30 |
| Midnight | 11:00 AM | 19:00 |
| Sunrise | 11:30 AM | 19:30 |
| Sunset | 2:30 PM | 22:30 |
| Midnight | 3:00 PM | 23:00 |
| Sunrise | 3:30 PM | 23:30 |
| Sunset | 6:30 PM | 2:30 |
| Midnight | 7:00 PM | 3:00 |
| Sunrise | 7:30 PM | 3:30 |
| Sunset | 10:30 PM | 6:30 |
| Midnight | 11:00 PM | 7:00 |
| Sunrise | 11:30 PM | 7:30 |
Effectively, the sun moves faster at night than during the day. However, an equivalent model is that the sun's orbit is uniform and circular but not
centered on the
world (yes, this implies that in Second Life the sun orbits the world rather than the other way around). The true center of the sun would then be at a point well above the horizon, such that the ratio of day-to-night is approximately 3:1. The
normal of the sun's orbital plane would appear to be tilted about 45 degrees on the
global x-
axis, although it varies more than +/- 5 degrees over a Second Life year (which is approximately 10 days long).
For all intents and purposes, the sun can be considered infinitely far away compared to the
scale of the world. That is, its direction (and
light) is uniform not only over the entire
simulator but over the entire world. The exception is that owners of private islands can fix the position of the sun so that its direction may be different from the direction seen in the majority of the world.
Although a rare occurrence, it is possible for the
Lindens to override the phase
offset of the sun's orbit, and to even lock it in place. Since this happens worldwide, it is likely that the sun's location is actually controlled from a central source rather than by a deterministic model that is duplicated on each simulator.
One possible application for this function is to determine whether it's day- or nighttime. The following script simply uses the z-axis of the sun's
vector to find out if the sun is above or below the horizon:
integer night=0; // 0 = daytime, 1 = nighttime
default
{
state_entry()
{
llSetTimerEvent(300); // Check every 5 minutes
}
timer()
{
vector sun = llGetSunDirection();
if (sun.z <= 0) night = 1; // Sun is below the horizon
else if (sun.z > 0) night = 0; // Sun is above the horizon
}
touch_start(integer total_number)
{
if (night == 1) llSay(0, "It's nighttime.");
else if (night == 0) llSay(0, "It's daytime.");
}
}
If the complete script is to behave different at night, an additional script
state may be a better solution than checking a variable:
Q: Can I set the sun position with a script? Debug mode lets you move the sun.
A: No. Debug mode only changes what you see, not what other people see, or what llGetSunDirection sees. If you own a private island, the estate tools can let you change the sun position within your island, but you can't do that with a script either. llGetSunDirection will get the correct sun position in a private sim.
There was once a footnote here claiming that a Linden said the sun and moon actually do move independently but that an eclipse would not occur for at least 500 RL years. It turns out that this is incorrect; the sun and moon are, in fact, always directly opposite each other.
Functions |
Simulator |
Weather |
Time |
Light