I know that there has got to be a simple fix for this (at least I hope!) Below is the script I'm using for my rocking chair. My problem is that when I turn the chair to face another direction it will reset itself to the original position when you click to begin rocking. I would love to be able to turn the chair to face any direction and have it rock as expected when clicked. I'm not even partially lsl literate, so any help from those more knowledgable than me is greatly appreciated! integer swing=FALSE; //So it starts out NOT swinging
float time=0.01; //Decreasing this (on it's own) makes the swing move FASTER and vice versa
integer steps=12; //The total number of steps in the swing's path. More steps=smoother swing. More steps (alone) means slower swing too - time for a complete swing cycle is steps * time (so 4.8 s with the default settings).
integer swingDegrees = 10; //How far from the vertical the swing moves
//If you play from here on down you might break the script. Do so at your own risk. There are no comments - just to encourage you NOT to play.
integer i=1;
float swingRad;
vector normal;
rotation Inverse(rotation r)
{
r.x = -r.x;
r.y = -r.y;
r.z = -r.z;
return r;
}
rotation GetParentRot()
{
return Inverse(llGetLocalRot())*llGetRot();
}
SetLocalRot(rotation z)
{
llSetRot(z*Inverse(GetParentRot()));
}
default
{
state_entry()
{
normal = llRot2Euler(llGetRot());
swingRad=DEG_TO_RAD*swingDegrees;
llSetTouchText("Rock");
}
touch_start(integer num)
{
if(swing)
{
swing=FALSE;
llSetTouchText("Rock");
}
else
{
swing=TRUE;
llSetTouchText("Stop swing");
llSetTimerEvent(time);
}
}
timer()
{
float stepOffset=(float)i/steps*TWO_PI;
if(i>steps) i=1;
if(swing==FALSE && (i==steps || i==steps/2))
{
llSetTimerEvent(0.0);
SetLocalRot(llEuler2Rot(<normal.x + swingRad*llSin(stepOffset), normal.y, normal.z>));
} else
{
SetLocalRot(llEuler2Rot(<normal.x + swingRad*llSin(stepOffset), normal.y, normal.z>));
i++;
}
}
moving_end()
{
normal=llRot2Euler(llGetRot());
}
}