Move Up and Down

Written by: Headmaster
// Makes an object go up or down, gradually, when touched.
// In order to make it a gradual movement, it uses a physical
// object, which means it might be a little wobbly ...
//
// Update: Jan 2012
//  Add correction factor to correct for but SVC2441, when an
//  object will descend too fast.
//
//  Kimm Paulino
//  Written for Nicollette Arabello, November 2009
//
 
integer gState;
integer DOWN=0;
integer GO_UP=1;
integer UP=2;
integer GO_DOWN=3;
 
float MOVE_DAMPING=4.0;
float MOVE_TIME=4.0;
float DOWN_CORRECTION=1.5;  // Use trial-and-error to correct for SVC-2441
 
// Move to 2m above starting position
vector gOffset = <0.0, 0.0, 2.0>;
vector gStartPosition;
 
default
{
    state_entry()
    {
        // Use physics so that can use MoveToTarget
        gStartPosition = llGetPos ();
 
        // Stop the object rotating
        llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, FALSE);
        llSetStatus(STATUS_PHYSICS, TRUE);
        llMoveToTarget (gStartPosition, MOVE_DAMPING);
        llSetTimerEvent (MOVE_TIME);
    }
 
    on_rez(integer n)
    {
        llResetScript();
    }
 
    timer ()
    {
        if (gState == DOWN)
        {
            gState = GO_UP;
            llMoveToTarget(gStartPosition + gOffset, MOVE_DAMPING);
            gState = UP;
        }
        else if (gState == UP)
        {
            gState = GO_DOWN;
            // Need to compensate (a bit) for SVC-2441
            llMoveToTarget(gStartPosition, MOVE_DAMPING*DOWN_CORRECTION);
            gState = DOWN;
        }
    }
}