Jump to content

Help with script


kury
 Share

You are about to reply to a thread that has been inactive for 4362 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I have a script that works pendulum continuous mode (touch Start) but I needed it to work only for 5 seconds. Could help?
The script is this:

integer swing=FALSE;
float time=0.3;
integer steps=12;
integer swingDegrees = 30;


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("Swing");
}
touch_start(integer num)
{
if(swing)
{
swing=FALSE;
llSetTouchText("Swing");
}
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, 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());
}

}

 

Link to comment
Share on other sites

You just want the pendulum to stop swinging after 5.0 seconds?  Start a stopwatch when you touch the object to start it and monitor the stopwatch every time your timer event triggers.  Kill the timer when it hits 5.0 seconds ....

integer swing=FALSE;float time=0.3;integer steps=12;integer swingDegrees = 30;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("Swing");	}	touch_start(integer num)	{		if(swing)		{			swing=FALSE;			llSetTouchText("Swing");		}		else		{			llResetTime();  //Here's the time when the pendulum starts swinging			swing=TRUE;			llSetTouchText("Stop swing");			llSetTimerEvent(time);		}	}	timer()	{		if (llGetTime() >= 5.0)	//Pendulum has been swinging for 5.0 seconds, so stop.		{			llSetTimerEvent(0.0);		}		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());	}}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4362 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...