Who Is Online

1
Online

Tuesday, 26 September 2017 05:36

Basic Physical Sliding Door Script

// ********************************************************************
//
// Basic Physical Sliding Door Script
// by SimonT Quinnell 
// 11/07/2009
//
// NOTE: If you are going to reposition the door, do it while the door is closed.
//  Otherwise it will try and use the old close position as a reference point.
//
// Licensed under the "OpenCollar License"
// Ie. Licensed under the GPLv2, with the additional requirement that these scripts remain "full perms" in Second Life.
//
// Edit: Simplified the script to be just a basic move script .. removed the sound triggers (5/1/2010)
//
// ********************************************************************
 
 
// ********************************************************************
// CONSTANTS
// ********************************************************************
 
// Movement Constants
vector      OFFSET = <-2.0, 0.0, 0.0>;      // Directional offset for moving the door in x,y,z coordinates
float       OPENTIME = 3.5;                 // Time taken to open door
float       CLOSETIME = 3.5;                // Time taken to close door
 
 
// ********************************************************************
// Variables
// ********************************************************************
 
vector      vPosition;
rotation    rRot;
float       omega=0.0;
vector      vTargetPos;
integer     bOpen = FALSE;
integer     bMoving = FALSE;
 
 
// ********************************************************************
// Functions
// ********************************************************************
 
 
MoveDoor()
{    
    if(!bOpen)
    {   // Initial conditions
        bOpen = TRUE;                
        rRot = llGetRot();
        vPosition = llGetPos();
 
        // Target Position
        omega=OPENTIME/llVecDist(<0,0,0>,OFFSET);
        vTargetPos = vPosition+OFFSET*rRot;
 
        // Set the timer to cleanup position
        llSetTimerEvent(OPENTIME);        
    }else
    {        
        bOpen = FALSE;
 
        // Target Position
        omega=CLOSETIME/llVecDist(<0,0,0>,OFFSET);
        vTargetPos = vPosition;
 
        // Set the timer to cleanup position
        llSetTimerEvent(CLOSETIME);
    }
 
    // Set Door Physical and move it
    bMoving = TRUE;
    llSetStatus(STATUS_PHANTOM, TRUE);
    llSetStatus(STATUS_PHYSICS, TRUE);
    llMoveToTarget(vTargetPos,omega);
}
 
 
default
{            
    state_entry()
    {   // Initial conditions
        rRot = llGetRot();
        vPosition = llGetPos();
    }    
 
    touch_start(integer num_detected)
    {
        MoveDoor();
    } 
 
    timer()
    {
        // Clean up Position
        bMoving = FALSE;
        llSetTimerEvent(0.0);
        llSetStatus(STATUS_PHYSICS, FALSE);
        llSetStatus(STATUS_PHANTOM, FALSE);         
        llSetPrimitiveParams();        
    }
}

 

Flash Scratch to SL - Your Scripting Tool

Script ImageNeed to write a LSL script and don't know how to script?  I know I hate trying to get my head around LSLS when I an in a time crunch. So why not give Flash Scratch a try! Its a great tool for learning and scoding your own scripts for Second Life without having to pay someone to do it and without a crash course in LSL

A Huge thanks to John Bennet of ATLAS Institute at University of Colorado and Eric Rosenbaum at MIT for writing Scratch for SL to begin with.

Read more: Flash Scratch to SL - Your Scripting Tool