Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Object knowing which way is forward

Mickey James
Registered User
Join date: 4 Nov 2006
Posts: 334
02-18-2007 05:32
This is probably a basic question but I'm fairly new to scripting so please bear with me.

I'm trying to build a cabinet with drawers that open and close when touched. I used llSetPos to move it along the X axis and it works perfectly ... until I turn the cabinet to face another direction. Then they go shooting through the sides or back.

How do I get the drawers to know which way is "forward" and move in that direction no matter how the cabinet is oriented?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-18-2007 08:26
From: Mickey James
This is probably a basic question but I'm fairly new to scripting so please bear with me.

I'm trying to build a cabinet with drawers that open and close when touched. I used llSetPos to move it along the X axis and it works perfectly ... until I turn the cabinet to face another direction. Then they go shooting through the sides or back.

How do I get the drawers to know which way is "forward" and move in that direction no matter how the cabinet is oriented?


you basically need to take into account the rotation of the root prim. To do so multiply by the root prim rotation.
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
02-18-2007 11:14
The function to use is llGetRootRotation(). ;)
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
02-18-2007 11:29
Search these forums for posts containing the words rotation and quaternion. Basically, yu either have to convert from local rotation to world rotation, or you have to use rotations relative to the root prim.
Mickey James
Registered User
Join date: 4 Nov 2006
Posts: 334
02-18-2007 15:58
I'd kind of figured that was the right direction to go in, but I don't know how to actually write the code. But at least now I have it confirmed that I'm looking in the right place.
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
02-18-2007 16:02
Here's the code. You'll need to wrap some more code around it to make it work, such as creating a touch event, managing the open/close state, declaring the necessary variables and so forth.

The variable pivot takes the values +1 or -1, and controls the direction of swing (clockwise/counterclockwise)

CODE

integer open()
{
rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,PI/4*pivot>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
return TRUE;
}
integer close()
{
rotation rot = llGetRot();
rotation delta = ZERO_ROTATION;
delta = llEuler2Rot(<0,0,PI/4*pivot*-1>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
return FALSE;
}
Mickey James
Registered User
Join date: 4 Nov 2006
Posts: 334
02-18-2007 19:36
Thanks! The touch event and sequence of states etc., I already have done. This is the part that was not working. I'll try incorporating this.
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
02-18-2007 20:52
That script is for a rotating object. It only changes your rotation, not your drawer position. I would not think that you want to change the drawer's rotation.

I do not have access to my code but from memory you need a move vector that gives the distance you want to move when your object has zero rotation (when all the rotation boxes in your edit box are zero), then you multiply that vector by llGetRot () and add that to llGetPos ().

Something like:
CODE

vector moveVector = <1,0,0>; // adjust this for movement when the drawer has 0 rot
llSetPos (llGetPos () + moveVector * llGetRot ();


Not tested, and someone might like to show how to alter this to move a linked drawer.
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
02-19-2007 05:15
the script I gave is from a working door script. I should have mentioned however that it needs to go into a hing prim to which a door is attached, or you could get by with a single prim if you cut the door to half its size so the pivot point is down the center.
Mickey James
Registered User
Join date: 4 Nov 2006
Posts: 334
02-19-2007 06:28
Oh, no. This is a drawer that needs to slide in and out, not a hinged door. I'll keep the code for future reference, though.
Mickey James
Registered User
Join date: 4 Nov 2006
Posts: 334
02-19-2007 07:07
edd44. that got me where I needed to be. Thanks.