Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Relavit position from Global position

Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
04-20-2009 20:12
I want to, by script, position several objects (children prims) relative to a central object (parent prim), but using Global co-ordinates - all prims will be in the same sim and within 10 metres of the parent. Preferrably I want to use the prim name, not its key.

Can it be done? and if so how?
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
04-20-2009 21:25
What you're saying doesn't really make much sense, can you restate what you're trying to do, and be a little more descriptive?
_____________________
My tutes
http://www.youtube.com/johanlaurasia
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
04-20-2009 22:29
OK - point taken


Imagine you have a single prim called "parent" sitting in a region.

You then create three other prims called Child1, Child2 and Child3 somethere close by within the same region

I want to reposition them (using a script) to specific positions relative to the 'Parent' using global or world x,y,z co-ordinates.

The parent can be placed anywhere within the region.

Hope that is better - thanks for your interest
Cerise Sorbet
Registered User
Join date: 8 Jun 2008
Posts: 254
04-21-2009 00:45
You want region coordinates. Global coordinates look at the whole grid but that is not important here. When you say children do you mean all the prims are linked together?
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
04-21-2009 03:55
CODE

default {
touch_start(integer n) {
integer linkNum = 2;
vector childNewPos = <85,24,601>;
llSetLinkPrimitiveParams(linkNum,[PRIM_POSITION,childNewPos - llGetPos()]);
}
}

This is taking the destination and subtracting the root position to get the offset and then applying that to the child.
You could also throw in a magnitude check to make sure the move is less then 10 meters from the root position.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
04-21-2009 14:35
I'll assume you mean you have an offset, and you want the region coordinates from that for unlinked objects, right?

add your offset to the base objects detected position, there's your region coordinates

if you want it relative to the rotation of the base object, multiply the offset by the base objects rotation before adding it's position

moving, detecting, and/or messaging between the objects is up to the reader.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Aztral Aeon
Registered User
Join date: 22 Dec 2007
Posts: 34
04-21-2009 16:50
Heyaz.

vector Global2Local(vector vGlobalPos)
{
return vGlobalPos - llGetRegionCorner();
}
vector Local2Global(vector vLocalPos)//added just for symetry
{
return vLocalPos + llGetRegionCorner();
}

integer GetLinkNumberFromName(string szPrimName)
{
integer nTotalPrims = llGetNumberOfPrims();
integer i = 1;
while(i <= nTotalPrims)
{
string szTmpName = llGetLinkName(i);
if(szTmpName == szPrimName)
return i;

i++;
}
return -1;//not found
}
// This should do what you want if I'm understanding you correctly. Again, it's only for moving inside one sim. There is no error checking that the position you want to move to is within 10m of the last position.
MoveChildGlobal(vector vGlobal, string szPrimName)
{
vector vNextPos = Global2Local(vGlobal);//must convert to local coords since llSetLinkPrimitiveParams expects local vectors

integer nLinkNumber = GetLinkNumberFromName(szPrimName);//assumes all prims have unique names

if(nLinkNumber != -1)
llSetLinkPrimitiveParams(nLinkNumber,[PRIM_POSITION,vNextPos]);
else
llOwnerSay("Doh! " + szPrimName + " not found.";);

}

Honestly, what I would recommend you do would be just convert your global coords to local before any movement calls though.

Hope this helps.

~Az
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
04-21-2009 20:56
Az - thanks, I think you have hit it on the head - will test and see - Thanks everyone - seems I caused a little confusion :)