Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Automatic Sliding Door Help

kirkmegna Wombat
Registered User
Join date: 1 Feb 2006
Posts: 89
04-07-2006 02:37
Hey People,

I'm trying to have automatic sliding doors for my elevator system in my office that I'm building. The basic idea is when some one gets close to the doors (using volume detect) the doors slide open. I'll have this trigger something to make the elevator give the person a dialog box for what floor they want, etc.

What I am having problems with is I have no idea how to go about making the doors work. If some one is able to post some information on how to go about making a very basic script that will move an object sideways when someone walks into the phantom prim (invisible) infront of it.

Thanks in advance for the help guys!

Cheers,

Kirk Wombat
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
04-07-2006 03:12
I won't post the script in it's entirety (I'm a teacher IRL and think people should solve their own problems :p) but you've got two choices really... physical movement (e.g. llMoveToTarget) or non-physcial movement (llSetPos.

I'd strongly suggest llSetPos unless you need totally smooth movement for some reason. You might also want to set the movement vector into several steps if you use this approach to give the appearance of smoother movement, a single "jump" will give you really quick doors and looks OK.

The next step is where to move to... llGetPos will tell you the position the door is currently in. Adding an offset to that (a vector for the move required e.g. <0,1,0> to move 1m in a positive y direction (the other door would move <0,-1,0> to go the other way) which you'll have to identify for your setting (the arrows in world mode on edit will show you the directions, red is X, green is Y and blue is Z). If you want to go in local movement (or move along a non-main axis route) things like the vector * llGetRot() will generally work well, although if your doors don't move with the lift just turning the door the right way and setting the start and end positions will do it well.

Hope that helps!
kirkmegna Wombat
Registered User
Join date: 1 Feb 2006
Posts: 89
04-07-2006 07:18
Thanks for the reply, that helps out some what but i'm still confused as to how I use the volume detect function in order to cause this to happen. I have used movetotarget for the actual elevator and understand how the vectors work but I am confused in regards to what scripts go in child or parent prim and what they should include. A simple example anyone?
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
04-07-2006 07:53
Me again, so no script!

You need a detector prim (think beam across the corridor or a cone a là ultrasound ones).

That needs the llVolumeDetect() bit. I'd use an llWhisper() to talk to the doors to trigger the movement (so the doors would need a listen event), but you could link them all and use link messages (your doors would then become phantom though).

Good luck!
Jessica Margetts
Registered User
Join date: 23 Jan 2006
Posts: 18
Slidding Door Script, (Part 1)
04-09-2006 03:42
This script needs to be put into the doors you wish to slide open (one copy for each door).

The only 2 things that need to b changed are, on what axis do you want it to slide...and do you want to slide To (+) or From (-) on this axis. The script will judge by the size of the object how far to slide...

(Please look for these in the init() section
_________________________________________________________
float ScaleMove;

integer slideDir;
integer openDir;
integer isOpen;

key handle;

list scale;

string ScaleFull;
string ownerName;
string secretWord = ""; // This is a word that will be sent to the door with the open command,
// This way, only the doors you want this trigger to open will open,
// Please note, you must also set this veriable in the door you want to open;

vector openPos;
vector closePos;

init()
{
slideDir = 0; // 0 = X, 1 = Y, 2 = Z
openDir = 1; // 0 = "-", 1 = "+"

ScaleFull = (string) llGetScale();
scale = llParseString2List(ScaleFull, ["<", ", ", ">"] , []);
ScaleMove = llList2Float(scale, slideDir) * 0.8;

closePos = llGetLocalPos();

if (!slideDir) { openPos = <ScaleMove, 0, 0>; }
if (slideDir == 1) { openPos = <0, ScaleMove, 0>; }
if (slideDir == 2) { openPos = <0, 0, ScaleMove>; }

if (openDir)
{
if (!slideDir) { openPos = <ScaleMove, 0, 0>; }
if (slideDir == 1) { openPos = <0, ScaleMove, 0>; }
if (slideDir == 2) { openPos = <0, 0, ScaleMove>; }
} else {
if (!slideDir) { openPos = <-ScaleMove, 0, 0>; }
if (slideDir == 1) { openPos = <0, -ScaleMove, 0>; }
if (slideDir == 2) { openPos = <0, 0, -ScaleMove>; }
}
openPos = llGetLocalPos() + openPos;

ownerName = llKey2Name(llGetOwner());

llListen( 16, "", NULL_KEY, "" );
}

openDoor()
{
isOpen = 1;
llSetPos(openPos);
}

closeDoor()
{
isOpen = 0;
llSetPos(closePos);
}


default
{
state_entry()
{
init();
}

listen(integer channel, string name, key id, string message)
{
if (message == ownerName + " " + secretWord + " " + "SLIDE OPEN";)
{
openDoor(); llSetTimerEvent(2);
}
}

timer()
{
closeDoor();
}
}
Jessica Margetts
Registered User
Join date: 23 Jan 2006
Posts: 18
Slidding Door Script, (Part 2)
04-09-2006 03:44
Place this script within a prim (such as a matt or something), one for the inside of the doors, one for the outside. when you step on the matt or whatever, it will telll the doors to open.


_____________________________________________________________________
string ownerName;
string secretWord = ""; // This is a word that will be sent to the door with the open command,
// This way, only the doors you want this trigger to open will open,
// Please note, you must also set this veriable in the door you want to open;
default
{
state_entry()
{
ownerName = llKey2Name(llGetOwner());
}

collision_start(integer num_detected)
{
llSay(16, ownerName + " " + secretWord + " " + "SLIDE OPEN";);
}
}
kirkmegna Wombat
Registered User
Join date: 1 Feb 2006
Posts: 89
04-09-2006 03:46
Thanks so much thats a huge help! I've decided to use setscale for the doors opening and closing but I can incorperate all of the above, thanks again!
Jessica Margetts
Registered User
Join date: 23 Jan 2006
Posts: 18
04-09-2006 04:03
No problem at all :)

Was thinking of posting it in the script library :D
Jesseaitui Petion
king of polynesia :P
Join date: 2 Jan 2006
Posts: 2,175
05-20-2006 17:11
Great script.

Both of my doors open to the left though. How do I get the right door to slide to the right??
Ryder Spearmann
Early Adopter
Join date: 1 May 2006
Posts: 216
This is the MOST AWESOME door script! But...
01-03-2007 18:02
It seems that this two part door script, which is amazingly effective, has one conceptual flaw, and I wonder how easy it is to remedy.

This door, will only work if it is aligned to one of three world axis. This means that ANY deviation from a world axis, will break the door.

Should not the sliding be referenced somehow, to the LOCAL axis of the door?

If I were a decent scripter, I would have some idea of how to do this... I would guess it has something to do with adding llGetRot to the calculations in some way... or maybe there is something about the approach taken in this script that causes this to be difficult to do?

If anyone can see how this improvement could be added, please chime in!

Thx, and special thanks to the author of this script....!

Ryder
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-04-2007 00:16
Jessica,

Try posting inside php tags to improve readability of the code.

Also not sure why you are bothering with the round the houses way of getting the new vector?

Instead of using 0 and 1 for direction use -1 and 1 makes your calculations easier.
CODE

vector vpos = llGetScale() * 0.8 * openDir;
if (0 == slideDir) { openPos = <vpos.x, 0, 0>; }
else if (1 == slideDir) { openPos = <0, vpos.y, 0>; }
else if (2 == slideDir) { openPos = <0, 0, vpos.z>; }


Also build the compare string once inside the state_entry rather than everytime in the listen event i.e.

strExpectedMessage = ownerName + " " + secretWord + " " + "SLIDE OPEN";

then in the listen

if(strExpectedmessage == message)
Ryder Spearmann
Early Adopter
Join date: 1 May 2006
Posts: 216
Because it works :)
01-04-2007 01:57
Hi Newgate,

I think she did it that way because it works :) I tried your suggestion about building the expected message first, but for whatever reason, it failed to allow the door to work.

Had you any thoughts on how to make the script work for doors that are not aligned to a world axis?

-Ryder-
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-04-2007 02:30
From: Ryder Spearmann
Hi Newgate,

I think she did it that way because it works :) I tried your suggestion about building the expected message first, but for whatever reason, it failed to allow the door to work.

Had you any thoughts on how to make the script work for doors that are not aligned to a world axis?

-Ryder-


The code I posted will work.
If it isnt it is probably due to where you placed the code, it obviously has to be after the line to set the ownerName. Try dumping out both teh received and expected message and see whats missing.

The only other reason it wouldnt work would be if the owner of the door is different from the owner of the sensor.

As to your last question then yes, you just need to take into account the rotation by using llGetRot. This has been previously covered a number of times.
Malik Bode
Registered User
Join date: 27 Dec 2006
Posts: 23
Sound
07-15-2007 09:48
Hi, Great script. Thanks.

Does anyone know how to add an opening and closing sound to this.

I've tried by adding the following (not my own code) to your script

// change four lines underhere to change sound or volume

// change the open sound string to set another opening sound
string OpenSound = "cb340647-9680-dd5e-49c0-86edfa01b3ac";

float OpenVol = 1.0; // change to set opening volume

//change the close sound string to change sound or volume
string CloseSound = "e7ff1054-003d-d134-66be-207573f2b535";

float CloseVol = 1.0; // change to set close volume

float ScaleMove;

integer slideDir;
integer openDir;
integer isOpen;

key handle;

list scale;

string ScaleFull;
string ownerName;
string secretWord = "A1door1"; // This is a word that will be sent to the door with the open command,
// This way, only the doors you want this trigger to open will open,
// Please note, you must also set this veriable in the door you want to open;

vector openPos;
vector closePos;

init()
{
slideDir = 0; // 0 = X, 1 = Y, 2 = Z
openDir = 1; // 0 = "-", 1 = "+"

ScaleFull = (string) llGetScale();
scale = llParseString2List(ScaleFull, ["<", ", ", ">"] , []);
ScaleMove = llList2Float(scale, slideDir) * 0.7;

closePos = llGetLocalPos();

if (!slideDir) { openPos = <ScaleMove, 0, 0>; }
if (slideDir == 1) { openPos = <0, ScaleMove, 0>; }
if (slideDir == 2) { openPos = <0, 0, ScaleMove>; }

if (openDir)
{
if (!slideDir) { openPos = <ScaleMove, 0, 0>; }
if (slideDir == 1) { openPos = <0, ScaleMove, 0>; }
if (slideDir == 2) { openPos = <0, 0, ScaleMove>; }
} else {
if (!slideDir) { openPos = <-ScaleMove, 0, 0>; }
if (slideDir == 1) { openPos = <0, -ScaleMove, 0>; }
if (slideDir == 2) { openPos = <0, 0, -ScaleMove>; }
}
openPos = llGetLocalPos() + openPos;

ownerName = llKey2Name(llGetOwner());

llListen( 16, "", NULL_KEY, "" );
}

openDoor()
{
isOpen = 1;
llSetPos(openPos);
if(OpenSound != "";) llTriggerSound(OpenSound, OpenVol);
llSetTimerEvent(0);
}

closeDoor()
{
isOpen = 0;
llSetPos(closePos);
if(CloseSound != "";) llTriggerSound(CloseSound, CloseVol);
llSetTimerEvent(0);
}


default
{
state_entry()
{
init();
}

listen(integer channel, string name, key id, string message)
{
if (message == ownerName + " " + secretWord + " " + "SLIDE OPEN";)
{
openDoor(); llSetTimerEvent(2);
}
}

timer()
{
closeDoor();
}
}

It sort of works but the sound keeps repeating as you step over the second trigger on the other side of the door.

Any ideas greatly appreciated. I'm slowely learning to pull this code stuff apart and it's beinging to make sense.