Simple Second Life elevator script

05 February 2009

Here’s the script:

vector LIFT_TOP    = <112.,112.,81.5>;
vector LIFT_BOTTOM = <112.,112.,27.>;

Travelator(vector start, vector finish)
{
    float  distance = 0;
    float  progress = 0;
    float increment = 1;

    vector direction = finish - start;
    vector dir_normal = llVecNorm(direction);
    distance = llVecDist(finish, start);

    vector next_pos = start;

    llSetPos(next_pos);

    do
    {
        progress += increment;
        if (progress >= distance)
        {
            llSetPos(finish);
            return;
        }
        next_pos += increment * dir_normal;
        llSetPos(next_pos);
    } while (progress <= distance);

}

default
{
    state_entry()
    {
        llWhisper(0, "Going down...");
        Travelator(LIFT_TOP, LIFT_BOTTOM);
    }

    touch_start(integer num_detected)
    {
        state top;
    }
}

state top
{
    state_entry()
    {
        llWhisper(0, "Going up...");
        Travelator(LIFT_BOTTOM, LIFT_TOP);
    }

    touch_start(integer num_detected)
    {
        state default;
    }
}

The constants LIFT_TOP and LIFT_BOTTOM are the coordinates of the top and bottom points of the elevator. This script does not support multiple storeys or call buttons — rather, it’s something you should build upon, rather than use out of the box.

Have fun.