Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llSetPos with child objects

Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
07-25-2004 18:48
Could you gurus help me with llSetPos please?

Why is this section of code:

CODE
    touch_start(integer total_number)
{
vector location = llGetLocalPos();
llSay(0,(string)location);
llSetPos(<.25, 0, 0>);
}


Causing the child object to move along the Z axis?!?

As I understand llSetPos, this code above should have moved my child object only .25m along the x axis of my parent prim. Right now when I touch the object, both the parent and child are moving about 4-5 meters on all 3 axis.
Apotheus Silverman
I write code.
Join date: 17 Nov 2003
Posts: 416
07-26-2004 08:46
Remember that llSetPos() on a child prim moves that prim relative to its root prim. This means the movement is relative to the root prim's rotation as well. If your root prim's x axis is aligned with the world's z axis, then then the child will move along the world's z axis in this case.

I find that turning on the local axis option when dealing with child prim movement causes everything tp suddenly make sense.

As for your root prim moving 4-5 meters, you posted no code for the root prim so I can't say much about that except that it will of course drag all its children with it.
_____________________
Apotheus Silverman
Shop SL on the web - SLExchange.com

Visit Abbotts Aerodrome for gobs of flying fun.
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
07-26-2004 11:02
The root prim had no code in it, so there was no code to post.

What I finally figured out was wrong was the axis of the child and parent were not the same. As soon as I aligned them, things started to work fine.

But now I'm experiencing very bad problem with the float numbers involved in vectors and it's causing me a world of headache.
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
07-26-2004 11:25
From: someone
Originally posted by Aaron Levy
But now I'm experiencing very bad problem with the float numbers involved in vectors and it's causing me a world of headache.


'splain.
_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
07-26-2004 11:33
I'm using the grid to allign my objects perfectly.

When the prims are not linked, they are EXACTLY where they need to be for the scripts inside them to work. I have 6 prims linked together, each runnng along their own "track" prim I used for testing the scripts in them, so a total of 12 prims total, 6 of which are in motion.

When the moving prims are linked just to their individual "track", the script in them works perfectly... it moves the prim along the X axis in increments of .25 and when it reaches the end of the track (from -2.75 to +2.75), it reverses and goes back, and loops.

So when it's just the 2 prims linked together, they work fine. When I link all 12 together, 3-4 of the prims get WEIRD locations like -0.0004 and -0.0008 along the Y and Z axis. Because the script is looking for the vector of (<2.75,0,0>;) when the prim reaches the end of the track, it never finds its and keeps moving the prim forward forever, because the prim reaches the end of the track, it's actually at (<2.75,0.0008,0.0004>;). I thought I'd compensate for this by having the script look for 0.0008 and 0.0004, but I found that when I move the entire linked object, all the numbers change, when they should remain static, since they're all linked!

It's really frustrating and I don't know why float numbers are even being used.
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
07-26-2004 11:48
Ah.

Well, as has been said before, never do an == comparison on a float.

Something like this should work
CODE

float fDelta = 0.001;
integer floatAt(float fPos, float fTarget)
{
return llFabs(fTarget - fPos) < fDelta;
}

integer vectorAt(vector vPos, vector vTarget)
{
return floatAt(vPos.x, vTarget.x) &&
floatAt(vPos.y, vTarget.y) &&
floatAt(vPos.z, vTarget.z);
}
_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!