Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

move to relative position? -help!

Yamil Dagger
Registered User
Join date: 10 Jul 2007
Posts: 36
03-01-2008 01:04
Hello guys. I recently scripted a sliding door for a friend and it seemed to work great until we spun the house a bit. I told it to move along it's y axis but if you turn the house, that doesn't exactly work so well...

So my question is, how do I change this to move relative to it's rotation?


llSetPos(llGetPos()+<0, 0.4125 ,0>;);
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
03-01-2008 02:50
Assuming the door is a child prim then I think this will do the trick: llSetPos(llGetLocalPos() + <0, 0.4125 ,0>;);
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-01-2008 09:07
set position requires global coordinates so Pale's example won't do

for sliding doors that don't change size each part should have the folliwing
llSetPos( llGetPos() + offset * llGetRot() );
to acount for the house being rotated
offset is the amount to move (in OP's case: <0.0, 0.4125 ,0.0>;)

for rotating doors:
if the door hals a half cut single prim centered at the hinge spot (or an unlinked multiprim door with the half cut prim as a root) you only need to change the rotation using
llSetLocalRot( vRotArc * llgetRot() );

if the door is linked and multi prim you'll need to change the position rotated around the offset of where the doors hinge is, and correct it's rotation, for EACH PART using
CODE

llSetPrimitiveParams( [PRIM_POSITION, llGetPos() + (vVecOffset - vVecOffset * vRotArc) * llGetLocalRot(),
PRIM_ROTATION, vRotArc * llGetLocalRot] );


in both cases vRotArc should be the angle you want to swing the door, and can be calulated by
rotation vRotArc = llEuler2Rot( <0.0, 0.0, degrees * DEG_TO_RAD> );
where degrees a number (like 90)

all these formulas will work at any given angle (including if the house is tilted)
_____________________
|
| . "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...
| -
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
03-01-2008 10:41
From: Void Singer
set position requires global coordinates so Pale's example won't do

Not for a child prim. "If the script resides in a child prim in a link set, the pos is relative to the root prim...." (http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSetPos).
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-01-2008 11:08
doh, sure enough... and attachments use a local offset too...

guess we both got it wrong, it should've been

llSetPos( llGetLocalPos() + offset * llGetRot() );
_____________________
|
| . "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...
| -
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
03-01-2008 13:54
For a simple sliding effect llSetPos(llGetLocalPos() + <0, 0.4125 ,0>;) works for me. :)

I must confess the way I tend to do this is to put a script in the child prim that captures the relevant settings and then play them back. I would always use llGetLocalPos() and llGetLocalRot() in a child prim for positioning and rotating respectively.

Setting positions and rotations together can be a pain because llSetPrimitiveParams doesn't do local rotations, although this can be over come by 'adjusting' the rotation to the root:

llSetPrimitiveParams([PRIM_ROTATION, rotation / llGetRootRotation()]);

(as described in Lex Neva's discussion at: )

Personally, anything but simple rotations usually ends up with me going around in circles. ;)
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
03-01-2008 14:03
From: Pale Spectre
For a simple sliding effect llSetPos(llGetLocalPos() + <0, 0.4125 ,0>;) works for me. :)

Yep. Just remember that offset of <0, 0.4125, 0> is going to be in the coordinates of the root prim, not the child prim. For offsets relative to the child prim's axes, Void's solution works.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-01-2008 14:14
I thought even local positioning uses global axis?

it could be that it's relative to the root, which means if it's working once, the angle won't matter...

but for premade instalation it migh tbe safer to grab the rot, since there's no guaranteed the root and door will have the same rot.

::shrug:: live and learn I guess

EDIT: mut not get distracted by TV while posting, but Abby (NCIS) is hard to ignore.
_____________________
|
| . "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...
| -