# Three stages door

Please take a moment to consider if this thread is worth bumping.

## Recommended Posts

Hello! Trying to create a door script with a menu to open in three stages. open, half open and closed. How to do it better? What is responsible for the rotation of the object in this case? This is not for the home but photographic backgrounds.

##### Share on other sites

It depends on how your door is constructed, of course.  Consult the sticky thread at the top of this form about how to write door scripts to see what your options are.  Once you have that figured out, then it's just a matter of making the door do two 45 degree rotations, reverse, and do another two 45 degree rotations. Over and over again.

If you start with @Innula Zenovka's simple script, for example, you can split her 90 degree rotation into two and get

```integer intSwing =45;
rotation rotSwing;
vector vOffset;
integer iTouch = 1;  //Start with the door fully open ( = 1 ) or fully closed ( = -1 )

default{

state_entry()
{
rotSwing = llEuler2Rot(<0.0,0.0,(float)intSwing>*DEG_TO_RAD);  //45 degrees on the z axis
vector size = llGetScale();
vOffset = <(size.x*-0.5),(size.y*-0.5),0.0>;//open away from someone standing in front of face 2 -- that is, in front of the prim -- hinged on the left.
}

touch_start(integer total_number)
{
if ( iTouch == 1 || iTouch == -1)	// Reverse direction
{
rotSwing.s *=-1;
iTouch = -iTouch;
}
list l = llGetPrimitiveParams([PRIM_POS_LOCAL,PRIM_ROT_LOCAL]);
vector v = llList2Vector(l,0);
rotation r = llList2Rot(l,1);
llSetPrimitiveParams([PRIM_POS_LOCAL,v+(vOffset-vOffset * rotSwing)*r,PRIM_ROT_LOCAL,rotSwing*r]);
++iTouch;	// Prepare for the next step
}
}```

If your door is cut or rotates around different axes or has other geometric constraints, you'll start with a different basic script.  The approach is the same, though.  Think of it as simply rotating the door twice, reversing, and doing it again.

Edited by Rolig Loon
Cleaner wording
• 1
##### Share on other sites

18 hours ago, Rolig Loon said:

It depends on how your door is constructed, of course.  Consult the sticky thread at the top of this form about how to write door scripts to see what your options are.  Once you have that figured out, then it's just a matter of making the door do two 45 degree rotations, reverse, and do another two 45 degree rotations. Over and over again.

If you start with @Innula Zenovka's simple script, for example, you can split her 90 degree rotation into two and get

```
integer intSwing =45;
rotation rotSwing;
vector vOffset;
integer iTouch = 1;  //Start with the door fully open ( = 1 ) or fully closed ( = -1 )

default{

state_entry()
{
rotSwing = llEuler2Rot(<0.0,0.0,(float)intSwing>*DEG_TO_RAD);  //45 degrees on the z axis
vector size = llGetScale();
vOffset = <(size.x*-0.5),(size.y*-0.5),0.0>;//open away from someone standing in front of face 2 -- that is, in front of the prim -- hinged on the left.
}

touch_start(integer total_number)
{
if ( iTouch == 1 || iTouch == -1)	// Reverse direction
{
rotSwing.s *=-1;
iTouch = -iTouch;
}
list l = llGetPrimitiveParams([PRIM_POS_LOCAL,PRIM_ROT_LOCAL]);
vector v = llList2Vector(l,0);
rotation r = llList2Rot(l,1);
llSetPrimitiveParams([PRIM_POS_LOCAL,v+(vOffset-vOffset * rotSwing)*r,PRIM_ROT_LOCAL,rotSwing*r]);
++iTouch;	// Prepare for the next step
}
}```

If your door is cut or rotates around different axes or has other geometric constraints, you'll start with a different basic script.  The approach is the same, though.  Think of it as simply rotating the door twice, reversing, and doing it again.

Thank you very much! It works absolutely perfectly!