kury Posted August 15, 2012 Share Posted August 15, 2012 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 More sharing options...
Rolig Loon Posted August 16, 2012 Share Posted August 16, 2012 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 More sharing options...
kury Posted August 16, 2012 Author Share Posted August 16, 2012 Rolig Loon, Thank you for your cooperation. Link to comment Share on other sites More sharing options...
kury Posted August 16, 2012 Author Share Posted August 16, 2012 The run time functioned. Now how to make the object back to original position when you stop? Link to comment Share on other sites More sharing options...
Rolig Loon Posted August 16, 2012 Share Posted August 16, 2012 Just store the original position (probably in state_entry) and then reset to that position whenever you stop the pendulum in either touch_start or the timer event. I'd probably use llSetLinkPrimitiveParamsFast, which has no delay. Link to comment Share on other sites More sharing options...
Recommended Posts
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