Sliding Door

From Second Life Wiki
Revision as of 14:46, 13 January 2008 by Lee Ponzu (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<lsl> // Create door. X is up/down, Y is open close. // Put script in door. // Set door at closed position, then reset script.

// Touch to open or close, or closes on timer

vector pos; // closed position when script is reset vector opos; // open position rotation rot; float amt = 1.8; // how far to slide, in meters integer dir = -1; // direction to slide. change sign to switch float offset = 0.1; // a little in or out as opposed to left right. integer open; // TRUE is open. float delay = 20; // seconds to stay open integer slice = 4; // how many steps during open and close

slide( vector tgt ) {

   vector npos = llGetPos();
   vector delta = (tgt - npos)/slice;
   integer s;
   for( s=1; s < slice; ++s ) 
   {
       npos += delta;
       llSetPos( npos );
   }
   llSetPos(tgt);

}

close() {

       llSetTimerEvent(0);
       slide(pos);
       llSetPos(pos);  
       llSetRot(rot);
       open = FALSE;

}


default {

   state_entry()
   {
       pos = llGetPos();
       rot = llGetRot();
       opos = pos + dir*(<0,amt,offset>*rot);  // assumes x axis is UP
       open = FALSE;
   }
   on_rez(integer n)
   {
       llResetScript();
   }
   touch_start(integer total_number)
   {
       if( open )
       {
           close();
       }
       else
       {
           slide(opos);
           llSetTimerEvent(delay);
           open = TRUE;
       } 
       
           
   }
   
   timer()
   {
       close();
   }
         
   

} </lsl>