Building Tutorial | Updated 2025

How to Create Interactive Doors in LSL

Master the art of door scripting! Learn to build 5 types of doors from basic sliding doors to advanced security systems with auto-sensors and group permissions.

5 Complete Scripts
Copy & Paste Ready
90 Min Tutorial

Door Building Basics

Before You Start:

What you need:

  • A door prim (usually a flat box or thin cylinder)
  • Build permissions on your land
  • Basic understanding of LSL (see our LSL Beginner's Guide)
Understanding Door Movement
Sliding Doors

Move linearly along X, Y, or Z axis using llSetPos()

llSetPos(closedPos + <3,0,0>);

โ†”๏ธ Perfect for: Modern buildings, sci-fi settings, elevators

Swinging Doors

Rotate around a hinge point using llSetLocalRot()

llSetLocalRot(llEuler2Rot(<0,0,90*DEG_TO_RAD>));

๐Ÿšช Perfect for: Traditional buildings, medieval castles, homes

Type 1: Simple Sliding Door

The most basic door - slides horizontally when touched.

// Simple Sliding Door - Moves 3 meters along X-axis vector closedPos; // Original position vector openOffset = <3.0, 0.0, 0.0>; // How far to slide (3m on X-axis) float MOVE_SPEED = 1.0; // Movement speed (lower = faster) default { state_entry() { closedPos = llGetPos(); // Remember starting position llSay(0, "๐Ÿšช Sliding door ready. Touch to open."); } touch_start(integer num_detected) { llSay(0, "Opening door..."); // Slide door to open position smoothly vector targetPos = closedPos + openOffset; llSetPos(targetPos); // Wait 5 seconds then close automatically llSleep(5.0); llSay(0, "Closing door..."); llSetPos(closedPos); // Return to original position } }
Important Setup:
  1. Make sure door is NOT set to Physical (Edit โ†’ Features โ†’ Physical = unchecked)
  2. Adjust openOffset vector to match your door's slide direction:
    • <3,0,0> = Slide right (positive X)
    • <-3,0,0> = Slide left (negative X)
    • <0,3,0> = Slide forward (positive Y)
    • <0,0,3> = Slide up (positive Z)

Type 2: Swinging Door with Hinge

Traditional door that rotates 90 degrees on a hinge, like real-world doors.

// Swinging Door - Rotates 90 degrees on Z-axis hinge rotation closedRot; // Original rotation float SWING_ANGLE = 90.0; // Degrees to swing open default { state_entry() { closedRot = llGetLocalRot(); // Remember starting rotation llSay(0, "๐Ÿšช Swinging door ready. Touch to open."); } touch_start(integer num) { llSay(0, "Opening door..."); // Convert degrees to radians (LSL uses radians) float angleRadians = SWING_ANGLE * DEG_TO_RAD; // Create rotation around Z-axis (vertical hinge) rotation swingRot = llEuler2Rot(<0.0, 0.0, angleRadians>); // Apply rotation relative to closed position llSetLocalRot(closedRot * swingRot); // Auto-close after 5 seconds llSleep(5.0); llSay(0, "Closing door..."); llSetLocalRot(closedRot); // Return to original rotation } }
Changing Swing Direction

Modify the rotation axis:

  • <0,0,90> - Swing counter-clockwise
  • <0,0,-90> - Swing clockwise
  • <0,90,0> - Swing like a drawbridge
Hinge Placement

For proper swinging, the door prim's pivot point should be at the edge where the hinge is located. Edit โ†’ Features โ†’ Edit Linked โ†’ Select only the door โ†’ Adjust pivot in Build window.

Type 3: Automatic Sensor Door

Advanced door that opens automatically when someone approaches - no touching required!

// Automatic Sensor Door - Opens when avatars approach vector closedPos; vector openOffset = <0.0, 0.0, 3.0>; // Slide up 3 meters float SENSOR_RANGE = 5.0; // Detect within 5 meters float SENSOR_RATE = 1.0; // Check every 1 second integer isOpen = FALSE; default { state_entry() { closedPos = llGetPos(); // Start sensor that detects avatars llSensorRepeat("", NULL_KEY, AGENT, SENSOR_RANGE, PI, SENSOR_RATE); llSay(0, "๐Ÿค– Auto-sensor door active. Approach to open."); } // Triggered when sensor detects someone sensor(integer num_detected) { if (!isOpen) { isOpen = TRUE; llSay(0, "๐ŸŸข Presence detected - Opening..."); llSetPos(closedPos + openOffset); // Set timer to auto-close after 3 seconds of no detection llSetTimerEvent(3.0); } else { // Someone still nearby, reset auto-close timer llSetTimerEvent(3.0); } } // Triggered when sensor finds nobody no_sensor() { // Nobody nearby, timer will close the door } // Auto-close timer timer() { llSetTimerEvent(0.0); // Stop timer isOpen = FALSE; llSay(0, "๐Ÿ”ด Closing door..."); llSetPos(closedPos); } }
Sensor Customization:
  • Detection Range: Change SENSOR_RANGE (1.0 to 96.0 meters)
  • Detection Arc: PI = 180ยฐ forward, TWO_PI = 360ยฐ all around
  • Scan Frequency: Lower SENSOR_RATE = faster response (min 0.2 seconds)
  • Detect Objects: Replace AGENT with ACTIVE to detect scripted objects

Type 4: Key-Locked Security Door

Only the owner can open this door - perfect for private homes and secure areas.

// Security Door - Owner-only access with key check vector closedPos; vector openOffset = <3.0, 0.0, 0.0>; key ownerKey; default { state_entry() { closedPos = llGetPos(); ownerKey = llGetOwner(); // Get door owner's UUID llSay(0, "๐Ÿ” Security door activated. Owner access only."); } touch_start(integer num) { key toucher = llDetectedKey(0); // Get who touched string toucherName = llDetectedName(0); // Check if toucher is the owner if (toucher == ownerKey) { // AUTHORIZED - Open door llSay(0, "โœ… Access granted: " + toucherName); llSetPos(closedPos + openOffset); llSleep(5.0); llSetPos(closedPos); } else { // DENIED - Show access denied message llSay(0, "โŒ Access DENIED: " + toucherName); llPlaySound("00000000-0000-0000-0000-000000000000", 1.0); // Add buzzer sound UUID // Optional: Send IM to owner about unauthorized attempt llInstantMessage(ownerKey, toucherName + " tried to access your door."); } } }
Adding Multiple Authorized Users:

Replace the owner check with a list of allowed UUIDs:

list AUTHORIZED_USERS = [ "00000000-0000-0000-0000-000000000001", // User 1 UUID "00000000-0000-0000-0000-000000000002" // User 2 UUID ]; if (llListFindList(AUTHORIZED_USERS, [toucher]) != -1) { // User is in authorized list }

Type 5: Group Access Door

Allow access to all members of a specific group - perfect for clubs, stores, and community buildings.

// Group Access Door - Members of the door's group can open it vector closedPos; rotation closedRot; float SWING_ANGLE = 90.0; integer isOpen = FALSE; default { state_entry() { closedPos = llGetPos(); closedRot = llGetLocalRot(); // Make sure door is set to a group (Edit โ†’ General โ†’ Set group) llSay(0, "๐Ÿ‘ฅ Group door ready. Members of '" + llList2String(llGetObjectDetails(llGetKey(), [OBJECT_GROUP]), 0) + "' may enter."); } touch_start(integer num) { key toucher = llDetectedKey(0); // Check if toucher is in the same group as the door if (llDetectedGroup(0)) { // GROUP MEMBER - Grant access llSay(0, "โœ… Group member access: " + llDetectedName(0)); if (!isOpen) { isOpen = TRUE; // Swing door open rotation swingRot = llEuler2Rot(<0, 0, SWING_ANGLE * DEG_TO_RAD>); llSetLocalRot(closedRot * swingRot); // Auto-close after 5 seconds llSetTimerEvent(5.0); } } else { // NOT A MEMBER - Deny access llSay(0, "โŒ You must be a member of this group to enter."); // Offer to join group (requires group UUID) // llInstantMessage(toucher, "Click here to join: secondlife:///app/group/GROUP-UUID-HERE/about"); } } timer() { llSetTimerEvent(0.0); isOpen = FALSE; llSetLocalRot(closedRot); llSay(0, "๐Ÿ”ด Door closing."); } }
Group Door Setup:
  1. Right-click door โ†’ Edit
  2. Go to General tab
  3. Click Set button next to Group
  4. Choose your group from the list
  5. Check "Share with group" (optional but recommended)
  6. The door will now recognize members of that group!

Pro Tips & Enhancements

Add Sound Effects

Make doors more realistic with sounds:

llPlaySound("door_open_sound", 1.0);

Upload .wav files or use free sounds from LSL Library.

Smooth Movement

Use llSetKeyframedMotion for smoother animation:

llSetKeyframedMotion([targetPos, 2.0], []);

Creates smooth interpolated movement over 2 seconds.

Phantom Doors

Let people walk through while door is open:

llSetStatus(STATUS_PHANTOM, TRUE);

Set to FALSE when closing to make solid again.

Hover Text Status

Show door status above it:

llSetText("OPEN", <0,1,0>, 1.0);

Changes color and text based on door state.

๐Ÿ—๏ธ Start Building Interactive Doors!

Log into Alife Virtual and test these scripts on your own builds.