Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

help moving with llDetectedPos()

Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
07-14-2009 05:59
so i am workign on a map that will move pieces (linked with the map) to where you touch the map. i am using this on the map itself llDetectedTouchPos(0);

it then takes that and sends it to the piece to be moved. the problem is that the piece moves to the centoer of the object evey time no mater where its touched. this is comming in as a linked message and i am passing the vector as a string henc why i have to del sub string.

CODE

llSay(0, "i want to move to "+ message);//tells me the vector it is getting
string pos1 = llDeleteSubString(message, 0, 0);
string pos2 = llDeleteSubString(pos1,-1,-1);
llSay(0, pos2); //tells me the vector it is using
//llSetPos(llGetPos() + (vector)pos2);
llSetPrimitiveParams([PRIM_POSITION, (vector)pos2]);


but it keeps moving to the center of the object and i am lost some help would be hugely appericated
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
07-14-2009 06:14
You can leave the angle brackets on, the cast will want to see them.

In a child prim, positions (for either llSetPos or llSetprimitiveParams) are relative to the root, make sure that your root prim subtracts its own position before sending the coordinates along.

CODE

//root prim script
default {
touch_start(integer total_number) {
llMessageLinked(2, 0, (string) ((llDetectedTouchPos(0) - llGetPos())/ llGetRot()), "");
}
}


CODE

// child prim script
default {
link_message(integer sender, integer num, string str, key id) {
llSetPos((vector) str);
}
}


You might want to play a little to add an offset, but that's the basic idea.

---
(You could also use llSetLinkPrimitiveParams in the root prim's script and skip the whole link message and extra script, unless you need to do something else like llSetText that really needs a child prim script.)

CODE

//one prim version
default
{
touch_start(integer total_number) {
if (llDetectedTouchFace(0) == 0) {
llSetLinkPrimitiveParams(2, [PRIM_POSITION, (llDetectedTouchPos(0) - llGetPos()) / llGetRot()]);
}
}
}
Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
07-17-2009 23:19
thanks loads that did the trick.