Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

sun direction

Alicia Sautereau
if (!social) hide;
Join date: 20 Feb 2007
Posts: 3,125
08-30-2008 21:11
Time for me to hit the spotlights with an issue that will most of you laugh at :)

trying to make a solar panel to follow the sun and if it`s night return to it`s standard position
the panel works after throwing a multiplyer in and if not to picky, it rotates well following the sun when time lapping with the estate tools

the main problem i have is the ground prim that rotates the panel, been at it for the past 2 hours throwing the entire wiki at it trying to create a vector from the sun x and y position to rotate the base prim on the z axis

does anyone have/know a script that just follows the sun on the z axis? (horizontal rotate)?

math has never been my strongest point :(
Thanks
BamBam Sachertorte
floral engineer
Join date: 12 Jul 2005
Posts: 228
08-30-2008 21:37
You might try

CODE

vector sun = llGetSunDirection();

rotation sunRot = ZERO_ROTATION;

if (sun.z >= 0.0) {
sunRot = llAxes2Rot(<sun.x, sun.y, 0.0>, <-sun.y, sun.x, 0.0>, <0.0, 0.0, 1.0>);
}

llSetRot(sunRot);
Alicia Sautereau
if (!social) hide;
Join date: 20 Feb 2007
Posts: 3,125
08-30-2008 21:54
it`s finally rotating where it`s supposed to rotate to instead of every where else lol

thanks BamBam! :p
Alicia Sautereau
if (!social) hide;
Join date: 20 Feb 2007
Posts: 3,125
08-30-2008 22:07
might aswell throw it in if any one wants to play with it aswell as i`m doing it to just fill my island abit

root prim
CODE

integer night=0; // 0 = daytime, 1 = nighttime
vector sun;

default
{
state_entry()
{
llSetTimerEvent(5); // Check every 5 minutes
}
timer()
{
vector sun = llGetSunDirection();

if (sun.z <= 0) {
night = 1; // Sun is below the horizon
llSetLocalRot( <0, 0, 0, 0> );
} else if (sun.z > 0) {
night = 0; // Sun is above the horizon

rotation sunRot = ZERO_ROTATION;

if (sun.z >= 0.0) {
sunRot = llAxes2Rot(<sun.x, sun.y, 0.0>, <-sun.y, sun.x, 0.0>, <0.0, 0.0, 1.0>);
}

llSetRot(sunRot);


//llSay(0, (string)turn);
}
}
}


child prim
CODE

integer night=0; // 0 = daytime, 1 = nighttime
vector sun;

default
{
state_entry()
{
llSetTimerEvent(5); // Check every 5 minutes
}
timer()
{
vector sun = llGetSunDirection();
if (sun.z <= 0) {
night = 1; // Sun is below the horizon
llSetLocalRot( <0, 0, 0, 0> );
} else if (sun.z > 0) {
night = 0; // Sun is above the horizon
vector target = sun; // A vector to look at.

vector eul = <0, 180 -(sun.z * 60), 0>; //45 degrees around the z-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians rotation
rotation quat = llEuler2Rot( eul ); //convert to quaternion
llSetLocalRot( quat ); //rotate the object
}
}
}


the 180 in the rotation is just cause my prim is aligned wrong :p
5 second timer is for testing with instant rotation with estate tools, set it at 300/600 or so
during the night it will rotate back to basic position till the sun comes up (directly from the wiki :)

have fun :)