Second Life today in one place Gifts & freebies updated every hour 7 languages Free to list your store
12:49 SLT List your event+ List
Grid issue
  • Planned: Scheduled Billing Maintenance, Mon, Nov 16 09:30–10:30 SLT
  • Grid status: Unscheduled Group Chat Maintenance (investigating)
  • On now: Unitarian Universalist Saturday Service in UUtopia
  • On now: The Dharma of Community: Buddhist Society and the Householder
  • On now: SLCS Harvest Fest: Games, Music and Fun at Cheertopia
  • 14:00 SLT: NAD GOUGH Live at Moondance in Cascadia, 2:00 PM SLT
  • News: REZZ MALL: Second Life brands in one web mall
  • Viewer: Second Life Viewer 26.5 Adds Chat Modernization
  • Planned: Scheduled Billing Maintenance, Mon, Nov 16 09:30–10:30 SLT
  • Grid status: Unscheduled Group Chat Maintenance (investigating)
  • On now: Unitarian Universalist Saturday Service in UUtopia
  • On now: The Dharma of Community: Buddhist Society and the Householder
  • On now: SLCS Harvest Fest: Games, Music and Fun at Cheertopia
  • 14:00 SLT: NAD GOUGH Live at Moondance in Cascadia, 2:00 PM SLT
  • News: REZZ MALL: Second Life brands in one web mall
  • Viewer: Second Life Viewer 26.5 Adds Chat Modernization
LSL script

LSL door script: touch to open, closes by itself

Free LSL door script for Second Life. Touch to open and close, the door swings on its hinge and closes by itself after a few seconds. Sounds optional.

55 lines ·

A simple, reliable door script for Second Life. Touch the door and it swings open on its hinge; touch again to close it, or let it close by itself after a few seconds. It remembers where the closed door stands each time it opens, so you can move the door later and it still works.

lsl-door-script.lsl · 55 lines Check this script
// Touch Door with auto-close - free LSL script from WhatSL (https://whatsl.com/scripts/lsl-door-script)
// Free to use, change and put in your own creations, also ones you sell.
//
// Put this script in an upright door that is its own object (not linked to the house).
// The door's width must run along its X axis (the red arrow in the Edit window).
// Touch to open, touch again to close. It also closes by itself after AUTO_CLOSE seconds.

float   OPEN_ANGLE  = 90.0;  // degrees to swing; use -90.0 to open the other way
float   AUTO_CLOSE  = 10.0;  // seconds before it closes by itself; 0.0 = stay open
integer HINGE_SIDE  = 1;     // 1 = hinge on the +X edge, -1 = hinge on the -X edge
string  OPEN_SOUND  = "";    // optional: a sound name in the door's Contents, or a sound UUID
string  CLOSE_SOUND = "";

integer  gOpen = FALSE;
vector   gClosedPos;
rotation gClosedRot;

openDoor()
{
    // remember where the closed door is, so the door can be moved and still work
    gClosedPos = llGetPos();
    gClosedRot = llGetRot();
    vector size = llGetScale();
    vector hinge = gClosedPos + <HINGE_SIDE * size.x * 0.5, 0.0, 0.0> * gClosedRot;
    rotation turn = llEuler2Rot(<0.0, 0.0, OPEN_ANGLE * DEG_TO_RAD>);
    llSetLinkPrimitiveParamsFast(LINK_THIS, [
        PRIM_POSITION, hinge + (gClosedPos - hinge) * turn,
        PRIM_ROTATION, gClosedRot * turn
    ]);
    if (OPEN_SOUND != "") llPlaySound(OPEN_SOUND, 1.0);
    gOpen = TRUE;
    if (AUTO_CLOSE > 0.0) llSetTimerEvent(AUTO_CLOSE);
}

closeDoor()
{
    llSetTimerEvent(0.0);
    llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POSITION, gClosedPos, PRIM_ROTATION, gClosedRot]);
    if (CLOSE_SOUND != "") llPlaySound(CLOSE_SOUND, 1.0);
    gOpen = FALSE;
}

default
{
    touch_start(integer total)
    {
        if (gOpen) closeDoor();
        else openDoor();
    }

    timer()
    {
        closeDoor();
    }
}

Free to use, change and put in your own creations, also ones you sell.

How to set it up

  1. Make or rez your door. It must stand upright and be its own object, not linked to the house.
  2. Check that the door's width runs along its X axis (the red arrow in the Edit window). If not, rotate the door in the build tools or swap the size values.
  3. Open the Content tab, click New Script, paste the script and save.
  4. Touch the door. If it opens the wrong way, set OPEN_ANGLE to -90.0. If it turns around the wrong edge, set HINGE_SIDE to -1.

Settings

  • OPEN_ANGLE: how far the door swings, in degrees.
  • AUTO_CLOSE: seconds before the door closes by itself; 0.0 keeps it open until touched.
  • HINGE_SIDE: which vertical edge is the hinge.
  • OPEN_SOUND / CLOSE_SOUND: the name of a sound in the door's Contents, or a sound UUID. Leave empty for silence.

Tips

  • For double doors, put the script in both doors and set one to OPEN_ANGLE 90.0 and the other to -90.0.
  • Doors that are part of a linked house need a different method. The easiest fix is to unlink the door and keep it as its own object.

Frequently asked questions

Why does my door turn around its middle?

The script rotates around one edge it works out from the door's X size. If the door turns around the middle, its width is not along the X axis. Rotate the door so the red arrow runs along its width.

Can I lock the door?

This version opens for everyone. For a locked door, add a check at the start of touch_start, for example: if (llDetectedKey(0) != llGetOwner()) return;

Does the script cause lag?

No. It only runs when someone touches the door and when the timer closes it.

Check your own script: LSL syntax checker →

More scriptsAll scripts
LSL script · 69 lines

LSL sit and pose script for chairs and pose balls

Free LSL sit script for Second Life chairs, benches and pose balls: sit and play your own animation, set the sit position, hide the ball while in use.

LSL script · 96 lines

LSL tip jar script with thank-you message and total

Free LSL tip jar script for Second Life clubs, DJs, hosts and stores: quick pay buttons, a thank-you message, the total and last tipper in floating text.

LSL script · 101 lines

LSL gift giver script for freebies and group gifts

Free LSL gift giver for Second Life stores: touch to get every item as one folder, for everyone or only for group members wearing the group tag.