string xCommand = "cswing";
string yCommand = "cstop";
integer chan = 9;
integer swing=FALSE;
float time=0.4;
integer steps=12;
integer swingDegrees = 45;
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 x)
{
llSetRot(x*Inverse(GetParentRot()));
}
default
{
state_entry()
{
normal = llRot2Euler(llGetRot());
swingRad=DEG_TO_RAD*swingDegrees;
llSetTouchText("Swing"
;llListen(chan,"",NULL_KEY,""
;}
listen(integer channel, string name, key id, string msg)
{
if (msg == yCommand)
{ normal=llRot2Euler(llGetRot());
llSetTimerEvent(0.0);
}
if (msg== xCommand)
{
swing=TRUE;
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, normal.y, normal.z + swingRad*llSin(stepOffset)>
);} else
{
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + swingRad*llSin(stepOffset)>
);i++;
}
}
moving_end()
{
normal=llRot2Euler(llGetRot());
}
}
thanks a lot.