[Home] [Back To Scripts]

A Brief Tutorial for Door Script


1.  Make a prim cube.

2.  Edit object with these parameters:

    Size:
            x=0.25
            y=6
            z=3.5

    Path Cut:
             B=0.375
             E=0.875

3.  Put your script in contents of prim.


vector gPos;
 
default {
    state_entry() {
        llSetRot(llEuler2Rot(<0,0,0>));
    }
 
    touch_start(integer total_number) {
        gPos = llGetPos();
        llSetRot(llEuler2Rot(<0,0,PI/2>));
        llSetTimerEvent(2.0);
    }
    timer() {
        llResetScript();
        llSetPos(gPos);
    }
}

 
An alternative script using llSleep may work better in OpenLife Grid:

vector gPos;
 
default {
    state_entry() {
        llSetRot(llEuler2Rot(<0,0,0>));
        gPos = llGetPos();
    }
    touch_start(integer total_number) {
        llSetRot(llEuler2Rot(<0,0,PI/2>));
        llSleep(3.0);
        llSetRot(llEuler2Rot(<0,0,0>));
        llSetPos(gPos);
    }
}





A note about rotations in LSL:  This can be a tricky subject.  There are many tutorials and explanations of Euler rotations vs. quaternions, etc.  See  LSL wiki: Rotation for more study.  For the scope of this tutorial, this little diagram can be very useful:



degree to rad



You can see in the above script example that the door's initial rotation* 
is <0,0,0>.  In order to make it open 90 degrees on Z axis, you plug in "π/2"  or PI/2 for the z coordinate. The values here are expressed in radians, not degrees.  If you want it to open in the opposite direction, you can just put a minus sign in front of the value, or plug in the radian opposite on the chart (in this case: 3π/2).
If you want to use a radian such as "3π/2", you would type this in your script:  3*PI/The key here is to play around with the coordinates and see what happens.  You can't hurt anything.  Just save the original copy of your script so you have that as a template.  If you need to rotate your door prim to fit into an existing build, you'll need to adjust the initial rotation in the script to match the rotation of your prim door.  Let's say your door is positioned so that when you edit your prim, you see these rotation coordinates:

X=0
Y=0
Z=180

Your initial rotation in the script should look like this:

llSetRot(llEuler2Rot(<0,0,PI>));

You can see from the chart above that 270 degrees corresponds to
π radians. 

Then you would put your "open" rotation in, depending on which way you wanted the door to open.  You could use either:

llSetRot(llEuler2Rot(<0,0,3*PI/2>));

or:

llSetRot(llEuler2Rot(<0,0,-3*PI/2>));

or:

llSetRot(llEuler2Rot(<0,0,PI/2>));

or:

llSetRot(llEuler2Rot(<0,0,-PI/2>));

All these code lines will give you a 90 degree rotation, either one way or the other, from your initial rotation.  My gut feeling as a non-mathematician and non-coder is that which you choose matters alot in more complicated scripts, but for the sake of this simple door, it doesn't matter.





*expressed as a vector Euler rotation converted to quaternion rotation using llEuler2Rot.  This will become important to understand if you work with rotations, but is beyond the scope of this tutorial.  See  LSL wiki: Rotation for more study.