Reply
Rolig Loon
Posts: 23,842
Registered: ‎10-05-2009
0 Kudos

Linkable Multiprim Sliding Door

[ Edited ]

This simple script will operate a multiprim sliding door that you have linked to a larger structure. Each prim in the door must be named "DOOR", and none of the door prims may be the root prim of the linkset. Also, all prims in the door must have the same orientation.  As written, the script assumes that door prims all have their local Z axes horizontal and that the door is supposed to slide on its Y axis.   You could easily change that orientation by changing the order of X,Y,Z parameters in the vector <0.0, gDistance*gON, 0.0>.

The door will only open if you click on one of the door prims.

 

//Linkable Multiprim Sliding Door -- Rolig Loon -- March 2011

// All prims in the door must be named "DOOR", and none can be the root prim of the linkset

integer gON = 1; // Change to -1 to reverse the direction of opening
float gDistance; // Adjust to set the distance the door should move long its local Y axis

default { touch_start(integer total_number) { if (llGetLinkName(llDetectedLinkNumber(0)) == "DOOR") { integer i; for (i=2;i<=llGetNumberOfPrims();++i) { if (llGetLinkName(i) == "DOOR") { list temp = llGetLinkPrimitiveParams(i,[PRIM_POSITION,PRIM_ROT_LOCAL]); rotation local_rot = (rotation)llList2String(temp,1); vector local_pos = ((vector)llList2String(temp,0)- llGetPos())/llGetRot(); llSetLinkPrimitiveParamsFast(i,[PRIM_POSITION,local_pos + (<0.0,gDistance *gON,0.0>*local_rot),PRIM_ROTATION,local_rot/llGetRot()]); } } gON = (-1)*gON; } } }

ETA:  BTW, this script should not be placed in the door itself, but in the frame (or whatever the door is linked to).

 

Not as dumb as I look
Ceera Murakami
Posts: 2,678
Topics: 9
Kudos: 231
Registered: ‎02-25-2009
0 Kudos

Re: Linkable Multiprim Sliding Door

[ Edited ]

Reply to Rolig Loon - view message

Ohhh, that looks useful!

Of course, you could change "DOOR" in both the script and in the prim names to allow more than one of these in a linkset. As presented in your post, if I did a case-sensitive search and replace and changed "DOOR" with "Bedroom door" for one script, and with "Bathroom door" for another, the two doors should both work and co-exist happily in the same linkset. I have used that trick before with linkable doors using my own scripts.

As an added elegant touch, you might try using llSetObjectDesc( "open" ); to set the description of the door prim to open, or llSetObjectDesc( "closed" ); to set it to closed, and then use llGetObjectDesc(); to determine the current open or closed state of the door. That trick makes the state persist even if the scripts are reset or the linkset is picked up into inventory while the door happens to be open, and then rezzed back in-world. Without that trick, taking the item and re-rezzing it, or resetting the scripts, can make the script think it is starting with the door closed, when in fact it is open, and can make the door move the wrong way, going out of position and into the wall when you try to close it, instead of closing.

I'm popping in-world now to test a variation of your script that used that modification, and will post it here when I have one that works.

Resident
OlWolf
Posts: 3
0 Kudos

Re: Linkable Multiprim Sliding Door

Reply to Rolig Loon - view message

I'm brand new at this, and don't know what I'm doing wrong. I recreated the door to my shed into 3-linked parts, then C&Ped this script from "default" to the bottom in it's entirety as a new script in the wall next to the "DOOR".

When I got to "Save" - I did that, and then linked the parts together starting with the roof, and ending with the floor, and the door was somewhere in between - so I'd remember not to do it last.

Then I tested the door by 'touching' the wall with the included script.... didn't work.

Where'd I mess up?

Posts: 4,688
Registered: ‎09-15-2009
0 Kudos

Re: Linkable Multiprim Sliding Door

Reply to OlWolf - view message

For a start you'll have missed the global variables above 'default' - copy the whole script as Rolig has it.  Secondly you need to change gDistance to how far you want the prims to move.  ... There may be more, but that should get things moving

Occam's Razor (House version): the simplest explanation is invariably ... someone screwed up.
Void Singer
Posts: 7,475
Registered: ‎05-28-2009
0 Kudos

Re: Linkable Multiprim Sliding Door

Reply to Rolig Loon - view message

somehow missed this before... but there is a way to remove the caveat about needing all the pieces to have the same orientation... simply calculate from an arbitrary center how far it has to move, rotate it to be correct for the frame, then add that offset to the pieces.... since it's just and offset, the rotation of the part is irrelevant.

- Farewell to your ports and good luck to you all
Honored Resident
Pazzo Pestana
Posts: 54
0 Kudos

Re: Linkable Multiprim Sliding Door

Reply to Rolig Loon - view message

I've been trying to use this script to allow a single prim door, linked to a house, to slide along the Y axis and haven't succeeded.  As a test, I've linked the door to a single (root) prim and placed the script in that prim.  I've reset the script.  When I touch the door, nothing happens.  I've copied the entire script, including the variables.

... any ideas what I'm not doing correctly?

thanks, again, to Rolig for her reference.

Rolig Loon
Posts: 23,842
Registered: ‎10-05-2009
0 Kudos

Re: Linkable Multiprim Sliding Door

[ Edited ]

Reply to Pazzo Pestana - view message


Pazzo Pestana wrote:

[ ...] As a test, I've linked the door to a single (root) prim and placed the script in that prim.  I've reset the script.  When I touch the door, nothing happens.  I've copied the entire script, including the variables.

... any ideas what I'm not doing correctly?

[ ... ]


See my note in the OP >>> "BTW, this script should not be placed in the door itself, but in the frame (or whatever the door is linked to)."  Also, be sure that the door is named "DOOR".

Not as dumb as I look
Jo Yardley
Posts: 1,679
Topics: 147
Kudos: 23
Registered: ‎10-05-2009
0 Kudos

Re: Linkable Multiprim Sliding Door

Reply to Rolig Loon - view message

Thanks for the script, it seems to do what I want it to do except that once the door slides open, or in this case after the window slides up, I can't get the window to slide down again.

Everytime I click it, it just repeats its 'go up' move.

Enjoy Time Travel?
Come visit Berlin in the 1920s;
The 1920s Berlin Project sim
Jo Yardley
Posts: 1,679
Topics: 147
Kudos: 23
Registered: ‎10-05-2009
0 Kudos

Re: Linkable Multiprim Sliding Door

Reply to Jo Yardley - view message

Here is the script I've used;

 

// All prims in the door must be named "Mesh sash window glass", and none can be the root prim of the linkset
integer gON = 1; // Change to -1 to reverse the direction of opening
float gDistance; // Adjust to set the the door should move long its local Y axis
default
{
touch_start(integer total_number)
{
if (llGetLinkName(llDetectedLinkNumber(0)) == "Mesh sash window glass")
{
integer i;
for (i=2;i<=llGetNumberOfPrims();++i)
{
if (llGetLinkName(i) == "Mesh sash window glass")
{
list temp = llGetLinkPrimitiveParams(i,[PRIM_POSITION,PRIM_ROT_LOCAL]);
rotation local_rot = (rotation)llList2String(temp,1);
vector local_pos = ((vector)llList2String(temp,0)- llGetPos())/llGetRot();
llSetLinkPrimitiveParamsFast(i,[PRIM_POSITION,local_pos + (<0.0,gDistance *gON,0.5>*local_rot),PRIM_ROTATION,local_rot/llGetRot()]);
}
}
gON = (1)*gON;
}
}
}

 

Enjoy Time Travel?
Come visit Berlin in the 1920s;
The 1920s Berlin Project sim
Rolig Loon
Posts: 23,842
Registered: ‎10-05-2009
0 Kudos

Re: Linkable Multiprim Sliding Door

Reply to Jo Yardley - view message

That's because you're not reversing direction, Jo.   To go back down again, gON has to become -gON.  You omitted the minus sign, so nothing changes.

gON = (-1)*gON;

or, more simply

gON = -gON;

Not as dumb as I look