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.
What you need:
Move linearly along X, Y, or Z axis using llSetPos()
llSetPos(closedPos + <3,0,0>);
โ๏ธ Perfect for: Modern buildings, sci-fi settings, elevators
Rotate around a hinge point using llSetLocalRot()
llSetLocalRot(llEuler2Rot(<0,0,90*DEG_TO_RAD>));
๐ช Perfect for: Traditional buildings, medieval castles, homes
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
}
}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)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
}
}Modify the rotation axis:
<0,0,90> - Swing counter-clockwise<0,0,-90> - Swing clockwise<0,90,0> - Swing like a drawbridgeFor 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.
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_RANGE (1.0 to 96.0 meters)PI = 180ยฐ forward, TWO_PI = 360ยฐ all aroundSENSOR_RATE = faster response (min 0.2 seconds)AGENT with ACTIVE to detect scripted objectsOnly 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.");
}
}
}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
}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.");
}
}Make doors more realistic with sounds:
llPlaySound("door_open_sound", 1.0);
Upload .wav files or use free sounds from LSL Library.
Use llSetKeyframedMotion for smoother animation:
llSetKeyframedMotion([targetPos, 2.0], []);
Creates smooth interpolated movement over 2 seconds.
Let people walk through while door is open:
llSetStatus(STATUS_PHANTOM, TRUE);
Set to FALSE when closing to make solid again.
Show door status above it:
llSetText("OPEN", <0,1,0>, 1.0);
Changes color and text based on door state.
Log into Alife Virtual and test these scripts on your own builds.