Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Moving on local Axis, or something smarter?

Cierl DeCuir
Registered User
Join date: 18 May 2007
Posts: 4
07-06-2007 09:44
I just finished up scripting a set of sliding doors for a house I am working on. They work great, lockable / unlockable and openable via a dialog box, and they move just like I wanted but only if they are oriented the same way (with respect to world axis's) as they were when I made them.

if it helps, say I made the doors facing me in this position(top down view)

door----door

and when they are moving they slide open like this

door------------door.

When I rotate them 90 degrees they end up moving like this (top down view)
...door
.........|
.........|
.........|
..........door



I would like the doors to be a little more dynamic than that, so what I am really looking to do is figure out which axis they need to actually slide on, then change the vector so they move how they are supposed to regardless of orientation on the world axis.

I tried messing with llRot2Left and llRot2Fwd, but every vector I got with both functions was <0.0000, 0.0000, 0.0000. -1.00000> so even when I converted it to Euler format it was the same number, so I could not figure out a way to use that to detirmine which axis the door should open on.

This is my first programming / scripting project in several years to be honest. I based the actual door motion on this script /15/2b/1907/1.html

Any help would be appreciated, I mean I can just change the vector in the script itself, but if this ever ends up in something I might want to sell it needs to be more dynamic than that. Thanks in advance!
Dytska Vieria
+/- .00004™
Join date: 13 Dec 2006
Posts: 768
07-06-2007 09:59
That sounds complicated! I found what you need in old thread and used it in this simple script:

//Movement Direction
float X = 0.0;
float Y = 0.8;
float Z = 0.0;

vector Slide = <X, Y, Z>;
vector Pos;

integer door_open = FALSE;

integer open(string av_name) // Opens the door.
{
llSetPos(llGetPos() + ((Slide * -1) * llGetRot()));
return TRUE;
}
//- - - - - - - - - - - - - - - -
integer close(string av_name) // Closes the door.
{
llSetPos (llGetPos() + (Slide * llGetRot()));
return FALSE;
}
//- - - - - - - - - - - - - - - -




default
{
touch_start(integer total_number)
{
if (!door_open){
door_open = open(llDetectedName(0));
} else {
door_open = close(llDetectedName(0));
}
}

}
_____________________
+/- 0.00004
Cierl DeCuir
Registered User
Join date: 18 May 2007
Posts: 4
07-06-2007 13:41
Thanks, that worked like a charm. I am curious, since I sorta want to know -why- it works. I tried several times by outputting various related euler and rotation coordinates to figure out how multiplying the increment and direction movement expressed by <0.25, 0, 0> i(n my script) by the rotation of the prim comes up with the numbers needed to move it properly.

Said a better way, how does adding .25 to the local X axis (as in the example above) get translated to adding .25 in the local Y axis by multiplying by the rotation of the object? (when I tried it I rotated 90 degrees on the Z axis and it worked like a charm)

I figure it has something to do with how rotation variables interact but I can't for the life of me figure out how, should I just take that it works and run with it? Thanks for any information, and I appreciate the solution =)
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
07-06-2007 15:37
From: Cierl DeCuir
...how does adding .25 to the local X axis (as in the example above) get translated to adding .25 in the local Y axis by multiplying by the rotation of the object? ...

http://mathworld.wolfram.com/Quaternion.html
Cierl DeCuir
Registered User
Join date: 18 May 2007
Posts: 4
07-06-2007 18:27
Heh, completly blew my mind. Thanks for the link though!