Jump to content

Move a subset of links within a linkset at once


Wulfie Reanimator
 Share

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

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

Recommended Posts

This function moves a list of linked prims within a linkset so that the first link will be centered at target.
I've included an example where a set of 4 prims are rotated 0.5 meters from the center of the root over time.

SubLinksetMove(list links, vector target)
{
    list positions;
    integer length = llGetListLength(links);
    integer i;
    
    // Get local positions of all links.
    while(i < length)
    {
        integer prim = llList2Integer(links, i);
        list localPos = llGetLinkPrimitiveParams(prim, [PRIM_POS_LOCAL]);
        positions += localPos;
        ++i;
    }
    
    // Get each prim's position relative to the first prim.
    // Must be done in reverse because the first prim's pos is used.
    i = length-1;
    while(i >= 0)
    {
        vector primLocal = llList2Vector(positions, i);
        vector primRelative = primLocal - llList2Vector(positions, 0);
        positions = llListReplaceList(positions, [primRelative], i, i);
        --i;
    }
    
    // Start compiling the SLPPF arguments.
    i = 0; list data;
    while(i < length)
    {
        data += [PRIM_LINK_TARGET, llList2Integer(links, i),
                 PRIM_POS_LOCAL, target + llList2Vector(positions, i)];
        ++i;
    }
    
    llSetLinkPrimitiveParamsFast(1, data); // Do the thing!
}

vector dir = <0.5, 0, 0>;

default
{
    state_entry()
    {
        llSetTimerEvent(0.05);
    }
    
    timer()
    {
        SubLinksetMove([2, 3, 4, 5], dir * llEuler2Rot(<0, 0, llGetTime()>));
    }
}

Here's a short 5 second clip of it in-world.

P.S. There's some optional to-dos here, like setting rotation as well, and optimizing the code some. I chose not to nitpick with optimizations so the script could be as simple to follow as possible. For the non-scripters, this does not mean that the function is laggy.

Edited by Wulfie Reanimator
  • Like 2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2195 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...