Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llSetPos/llSetPrimitiveParams question

Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
04-04-2008 12:10
I think i know the answer to this, but thought I'd ask anyway.

I can move a child prim releative to the root prim ok, but is it possible to move the root prim relative to the rest of the link set without moving the whole object.

I suspect not, but thought I'd ask.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
04-04-2008 13:42
In a sense. What you really have to do to accomplish this is move ALL the child prims by the negative of the desired offset, and then the object itself. This will leave the location of the child prims unchanged, but the root prim (and the object's location, defined to be the same) will be moved. Something like (uncompiled, untested):

CODE

// If this is a child prim, offset is in the object's (root prim's)
// coordinate system. If this is a root prim, offset is in
// attachment coordinates if the object is attached, and global
// coordinates otherwise.
movePrim(vector offset)
{
vector pos = llGetLocalPos();

if (llGetLinkNumber() == 1) // root prim of multi-prim object
{
vector relOffset = offset/llGetLocalRot(); // in object (root prim) coordinates

integer nPrims = llGetNumberOfPrims();
integer linkIndex;
for (linkIndex = 2; linkIndex <= nPrims; ++linkIndex)
{
vector childPos = getChildPos(linkIndex);
llSetLinkPrimitiveParams(linkIndex, [ PRIM_POSITION, childPos-relOffset ]);
}
}

llSetPos(pos+offset);
}

// Returns a child prim position useful for llSetLinkPrimitiveParams() whether or not
// the object is attached. Assumes llGetObjectDetails() always works as llGetPos()
// called from the target prim.
vector getChildPos(integer linkIndex)
{
key child = llGetLinkKey(linkIndex);
vector childOffset =
llList2Vector(llGetObjectDetails(child, [ OBJECT_POS ]), 0)-
llGetRootPosition();

if (llGetAttached())
{
// See child of attachment in
// http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetPos
return childOffset;
} else
{
return childOffset/llGetRootRotation();
}
}
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
04-04-2008 14:23
Thanks for the reply Hewee

I thought something like that was the only solution, also considered unlink, move, relink then i looked at my problem again, which i never defined in th op.

the problem i had was a door, on collision i wanted to open it by resizing

that leaves what left stuck in the middle so you cant walk through. so i wanted to move it up.

After a cup of coffee it hit me, just cut the prim so the centre is at the top, no need to move at all, just re-size. /me bangs head on brick wall

thanks for the time you must have taken on your reply (code saved for future use)