Jump to content

set position of childprim using root position


testgenord1
 Share

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

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

Recommended Posts

Hi!
I would like to automatically set the position of a childprim on the same position as the root prim,  but 1 meter above the root prim.
This really should not be a problem, but for whatever reason, I cannot accomplish this.
The childprim always ends up several meters set away from the root prim in the x-position.
(The same also happens when I replace PRIM_POSITION with PRIM_POS.)

I can't figure out what is wrong.
Maybe you can find the mistake?

Thank you very much in advance!
Here is my script:

vector startpos;

default
{
    state_entry()
    {
        startpos = llGetPos();//Position of the rootprim
        llOwnerSay("startpos = " + (string)startpos);
        llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[PRIM_POSITION,startpos - <0.0,0.0,1.0>]);//Position of the childprim
    }
}
Link to comment
Share on other sites

Thank you for your quick reply.

I just don't understand why, but it doesn't seem to make any difference (that's what I meant with "PRIM_POS" in my original post, I really meant to write "PRIM_POS_LOCAL".
It leads to the same result.

The script seems to be logical that way.
I really can't see where the mistake is.

Any other ideas will be appreciated.

Link to comment
Share on other sites

A few things. llGetPos() isn't neccessarily the position of the root prim. for that you need http://wiki.secondlife.com/wiki/LlGetRootPosition.

so to fix your script you could say

default
{
    state_entry()
    {
        vector startpos = llGetRootPosition();//Position of the rootprim
        llOwnerSay("startpos = " + (string)startpos);
        llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[PRIM_POSITION,startpos + <0.0,0.0,1.0>]);//Position of the childprim
    }
}

But as Rolig suggested it would be less error-prone to just

default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[PRIM_POS_LOCAL,<0.0,0.0,1.0>]);//Position of the childprim
    }
}

 

  • Like 2
Link to comment
Share on other sites

2 hours ago, testgenord1 said:

1 meter above the root prim

The meaning of "above" might be a problem. If the root is rotated relative to region coordinates, motion of the child prim(s) will be relative to the root, not the region. You may actually want that <0,0,1> offset to be rotated through the root rotation (<0,0,1> / llGetRootRotation() or something like that).

 

Edited by Qie Niangao
"/" not "*" because we're COMPENSATING for that root rotation, to put it back into region coordinates
  • Like 1
Link to comment
Share on other sites

Thank you very much for your idea.
I've further simplified the script to avoid errors.
The position of the childprim is now supposed ot be the same as the root prim's.

Unfortunately it didn't help.
(Renaming LINK_ALL_CHILDREN to link number "2" also didn't make any difference.)

I tried some debugging and had a really bizarre result using the script below.
The newly created vector of the linked prim ("newpos") produced the following result:

[12:21] Primitive: startpos = <380.697083,  77.889473,  21.167229>
[12:21] Primitive: newpos = <391.888062,  80.507759,  21.724491>
 

I really don't get it.
 

default
{
    state_entry()
    {
        vector startpos = llGetRootPosition();//Position of the rootprim
        llOwnerSay("startpos = " + (string)startpos);
        llSetLinkPrimitiveParamsFast(2,[PRIM_POSITION,startpos]);//Position of the childprim
        vector newpos = llList2Vector(llGetLinkPrimitiveParams(2,[PRIM_POSITION]),0);
        llOwnerSay("newpos = " + (string)newpos);
    }
}

 

Link to comment
Share on other sites

Child prim positions are specified relative to the root, so if you try to set a child prim's position to "startpos" it will actually try to offset that child prim from the root by the region coordinates of the root prim. 

To put the child prim at the same location as the root, you'd set its position to <0,0,0> — that is, offset by nothing at all from that root position.

  • Like 1
Link to comment
Share on other sites

8 minutes ago, Qie Niangao said:

Child prim positions are specified relative to the root, so if you try to set a child prim's position to "startpos" it will actually try to offset that child prim from the root by the region coordinates of the root prim. 

To put the child prim at the same location as the root, you'd set its position to <0,0,0> — that is, offset by nothing at all from that root position.

Thank you very much, Qie Niangao.
So, using the same position as the root prim's for the child prim automatically creates an offset for the child prim's position?

Your advice seems to have done the trick.
I'm posting the script below.
Should I run into more problems, I'll come back again.

Thank you all for your help very much again! 🙂

default
{
    state_entry()
    {
        vector startpos = llGetRootPosition();//Position of the rootprim
        llOwnerSay("startpos = " + (string)startpos);
        llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[PRIM_POSITION,<0,0,1>]);//Position of the childprim +1 meter offset in z-direction
        vector newpos = llList2Vector(llGetLinkPrimitiveParams(2,[PRIM_POSITION]),0);
        llOwnerSay("newpos = " + (string)newpos);
    }
}

 

Link to comment
Share on other sites

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