Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sliding door when not square to XY axis

Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
07-15-2007 02:06
I have a sliding door script that works well as long as the door movement is square to the XYZ axis (well at least the XY axis)

Basic script bits are:
vector slide_by = <0, -2, 0>;
...
}
llTriggerSound("Door open", 0.5);
llSetPos(llGetPos() + slide_by);
status = "open";
}

Now is there a way to adjust this so that the door will slide properly if it is off the XY axis - is there a way to automatically read its location and adjust the movement?

Tarak
:-)
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-15-2007 02:42
Assuming this is working correctly when the door has a zero rotation, then I'd try rotating the "slide_by" offset to coincide with the door's rotation, something like:

llSetPos(llGetPos() + (llGetRot() * slide_by));

[edit: well, "something like" but not quite: the rotation has to be to the right of the vector, so to get it to compile, it would have to be "llSetPos(llGetPos() + (slide_by * llGetRot()))"... as Lee correctly describes.]
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
rotations and quaternions
07-15-2007 06:55
The good news is that this is easy. The bad news is that it is time for you to learn about quaternions...8-)

The general rule is that if you have a direction in terms of the local coordinates, you can convert it to world coordinates by multiplying by the rotation. There are lots of discussions in these forums and in the Wikis.

let c = llGetPos(), the current position.

suppose you want to slide to the right. That is an offset in the negative Y direction in SL, such as <0,-1,0> (in local coordinates), so the new position is

c + <0,-1,0>*llGetRot()

(I think 8-(
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
07-24-2007 22:46
Thanks for that
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
Simplest Linkable Sliding Door
07-25-2007 00:46
Here is a very simple script for a sliding door which works as a single prim, a discrete linked set, or as a single prim linked into a larger set (as long as it's not the root prim, in which case it can't move itself without moving everything.)

CODE

// simplest linkable sliding door by Boss Spectre.
// freely usable, no warranty expressed or implied.
// Caveats:
// - this will be subject to "prim drift" over time, due to floating point inaccuracies.
// - this script will move the entire object if used in a root prim.
//
// Features:
// - this script will move the entire object if used in a root prim.
//
vector move = <0, 2.0, 0>;
float direction = 1.0;
default
{
touch_start(integer total_number)
{
direction = -direction;
llSetPos(llGetLocalPos() + (move * direction) * llGetLocalRot());
}
}


To avoid prim drift, you'd have to store a base position for the movements, so you are always seeking to the same coordinates. This of course could lead to complications if the object is moved or re-linked, but could work ok when a child prim, as the linked object could be moved without affecting the local coords.