Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Prim local position without llGetLocalPos

Steven Kramer
Registered User
Join date: 7 Jun 2006
Posts: 6
08-02-2006 05:03
I have a small problem I need some help with. I have some linked prims and a script in the root prim. I need to get the local position of a child prim from within that script in the root prim.

I couldn't find an easy way, what I'm doing right now in the script in the root prim is roughly like this:
  1. Record child prim's key.
  2. Break the link between the prims. (needed for the sensor to work)
  3. Run a sensor on the key we just got.
  4. Get the difference between the position detected by the sensor and our global position. (the original root prim)

The problem is, the position I just calculated is slightly off from what I would get if I were to put a script in the child prim calling llGetLocalPos().

This doesn't seem to be a problem specific to the sensor, I created a small test case with the same results as follows:
  1. Create two prims, and link them. I created a sphere and a cube, and linked them so the sphere ended up being the root prim.
  2. Put the following script in the child prim: (in my case, the cube)
    CODE
    default {
    touch_start(integer num_detected) {
    vector rpos = llGetRootPosition();
    vector lpos = llGetLocalPos();
    vector gpos = llGetPos();

    llOwnerSay("Local position: " + (string)lpos);
    llOwnerSay("Recalculated: " + (string)(gpos - rpos));
    }
    }

  3. Touch the child prim and note the output:
    From: someone
    Local position: <0.08320, -0.13180, -0.29339>
    Recalculated: <0.16348, -0.12407, -0.26123>

As far as I can tell these should be the same, but they're not. It's just as much off as when I used the sensor before. Am I doing something wrong here? Is there an easier way to do this without putting a script in the child prim I'm trying to get the position from?
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
08-02-2006 06:19
From: Steven Kramer
Am I doing something wrong here?

If your root object is rotated i.e. not perfectly aligned with world axes, your calculated offset will be in world coordinates, while local offset is in coordinate system determined by rotation of root object (to see it rotate your root object to exactly 90 degree and you'll see the values will sort of match, but on swapped axes, so to speak)

the solution is simple, after calculating vector between root and child, "un-rotate" this vector by amount of rotation your root object has:

llOwnerSay("Recalculated: " + (string)((gpos - rpos) / llGetRootRotation() );
Damanios Thetan
looking in
Join date: 6 Mar 2004
Posts: 992
08-02-2006 06:20
You probably have to compensate for the rotation of either root or child prim. Or make sure they both have zero rotation.
_____________________
Steven Kramer
Registered User
Join date: 7 Jun 2006
Posts: 6
08-02-2006 06:36
That fixed it, can't believe it was that simple. :)
Thanks for the quick replies guys, much appreciated! :)
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-02-2006 11:16
Why don't you simply use a link message so the parent can query the child for its position and the child can reply? (Or the child can simply keep the parent appraised on a regular basis.)