Jump to content

Move a childprim along an axis of the root prim like a beam


MartinRJ Fayray
 Share

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

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

Recommended Posts

float fTimer = 10.0; //how long to go the entire distance
integer iSteps = 200; //how many steps to go from start to end
integer iLinknumber = 2; //link number of the moving prim
vector vAxis = <0.0,1.0,0.0>; //axis to move along. <1,0,0> is x-axis, <0,1,0> is y-axis, <0,0,1> is z-axis
integer iStep = 0; //control variable, don't change
default
{
    state_entry()
    { //start timer
        llSetTimerEvent((fTimer/iSteps));
    }
    timer()
    { //remove un-changeable axis-parameters from scale
        vector vScale = llGetScale();
        if (vAxis.x == 0.0) {vScale.x = 0;}
        if (vAxis.y == 0.0) {vScale.y = 0;}
        if (vAxis.z == 0.0) {vScale.z = 0;}
        if (iStep >= iSteps)
        { //reset step if last step was reached
            iStep = 0;
        }
        //set local position
        llSetLinkPrimitiveParamsFast(iLinknumber, [PRIM_POS_LOCAL, (-vScale / 2.0) + (vScale / iSteps)*iStep]);
        iStep++; //add 1 to step
    }
}

 

  • Like 1
Link to comment
Share on other sites

Very nice script.  Because someone asked in the LSL Scripting Forum, here's a version that moves all child prims in the linkset along the chosen direction, keeping their initial positions in the "non-beam" directions constant.  For example, if the chosen beam direction is <1.0,0.0,0.0>, the child prims move back and forth along X, while keeping local Y and Z positions fixed.

float fTimer = 10.0; //how long to go the entire distanceinteger iSteps = 200; //how many steps to go from start to endvector vAxis = <1.0,0.0,0.0>; //axis to move along. <1,0,0> is x-axis, <0,1,0> is y-axis, <0,0,1> is z-axisinteger iStep = 0; //control variable, don't changeinteger k;  // ON/OFF switchinteger toggle; // Reverse direction of slidelist gHome;     // Starting positions of child primsdefault{        touch_start(integer num)    {        integer i;        k = !k;        if (k)        {         //ON            for (i=2;i<=llGetNumberOfPrims();++i)             {   //Loop to get the starting positions of all child prims                gHome += [llList2Vector(llGetLinkPrimitiveParams(i,[PRIM_POS_LOCAL]),0)];            }            iStep = 0;  //Set slide position at zero            llSetTimerEvent((fTimer/iSteps));            llOwnerSay("on");        }        else        {   //OFF            for (i=2;i<=llGetNumberOfPrims();++i)            {   //Loop to reposition all child prims at their starting positions                llSetLinkPrimitiveParamsFast(i, [PRIM_POS_LOCAL, llList2Vector(gHome,i-2)]);            }            gHome = []; // Empty the home position vector list            llSetTimerEvent(0);            llOwnerSay("off");            //  llResetScript();        }    }    timer()    { //remove un-changeable axis-parameters from scale        vector vScale = llGetScale();        if (vAxis.x == 0.0) {vScale.x = 0;}        if (vAxis.y == 0.0) {vScale.y = 0;}        if (vAxis.z == 0.0) {vScale.z = 0;}        if (iStep >= iSteps)        {            toggle = -1;                               }               else if (iStep <= 0)        {            toggle = 1;               }        integer i;        for (i=2;i<=llGetNumberOfPrims();++i)        {   // Loop for all child prims            llSetLinkPrimitiveParamsFast(i, [PRIM_POS_LOCAL, llList2Vector(gHome,i-2) + (vScale / iSteps)*iStep]);            iStep = iStep + toggle; //add 1 or -1 to step        }    }}

 

  • Like 1
Link to comment
Share on other sites

  • 3 years later...
You are about to reply to a thread that has been inactive for 2285 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...