Move Up and Down and Rotate

Written by Kitsune
// Makes an object go up or down, gradually,
// with a slow rotation.
//
// Includes option for touch control.
//
// Warning:
//  * The animation will go a little weird if it is taken into inventory
//     whilst moving.
//  * It can't be used with a rezzer unless it is stopped (so
//     touch control is mandatory to turn it back on).
//
// Thanks to the members of the Advanced Scripters of SL group.
//
// Update Jan 2013: Added touch.
//
//  Kimm Paulino
//  February 2012
//
 
float gMoveTime = 4.0;                // Time for each movement
vector gOffset  = <0.0, 0.0, 2.0>;    // Where to move to (and back from)
vector gDegRot  = <0.0, 0.0, 180.0>;  // rotation to apply going up, then going down again 
integer gTouchControl = TRUE;           // FALSE to disable touch
 
integer gState;
 
default
{
    state_entry ()
    {
        gState = 0;
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);
    }
 
    touch_start (integer num_detected)
    {
        if (gTouchControl)
        {
            // 0 = first time; 1 = off; 2 = on
            if (gState == 0)
            {
                gState = 2;
                llSetKeyframedMotion (
                    [
                        gOffset, llEuler2Rot (gDegRot*DEG_TO_RAD), gMoveTime,
                        -gOffset,  llEuler2Rot (gDegRot*DEG_TO_RAD), gMoveTime
                    ],
                    [KFM_MODE, KFM_LOOP]);
            }
            else if (gState == 1)
            {
                // turn on
                gState = 2;
                llSetKeyframedMotion ([], [KFM_COMMAND, KFM_CMD_PLAY]);
            }
            else
            {
                // turn off
                gState = 1;
                llSetKeyframedMotion ([], [KFM_COMMAND, KFM_CMD_PAUSE]);
            }
        }
    }
 
    on_rez (integer n)
    {
        llResetScript();
    }
}