Flight Assist

From Second Life Wiki
Jump to: navigation, search

Created by Kira Komarov.

A flight band or a flight plume will allow you to fly above the 200m limit. If you have ever wondered what the script looks like which allows you to fly to higher altitudes, here is a free implementation of such a device. To use this device, simply drop it in a prim and wear it; you can also drop it in a prim which is already attached to your body.

The script also responds to commands on the main chat (without the quotes):

  • by saying "fly on", you enable the flight assist. By default, when you attach the prim to yourself, or place it in a prim you are already wearing, the flight assist will automatically be turned on.
  • by saying "fly off", you can disable the flight assist.
  • by saying "fly faster", you can increase your speed while flying.
  • by saying "fly slower", you can decrease your flying speed.

The way the script works is by capturing your forward, backward, left, right, up and down controls and whenever you press one of them, the script applies a physical force to your avatar. This is roughly how vehicles work in SL too.

//////////////////////////////////////////////////////////
// [K] Kira Komarov - 2011, License: GPLv3              //
// Please see: http://www.gnu.org/licenses/gpl.html     //
// for legal details, rights of fair usage and          //
// the disclaimer and warranty conditions.              //
//////////////////////////////////////////////////////////
 
float speed = 0.5;
 
default {
 
    state_entry() {
        llRequestPermissions(llGetOwner(),PERMISSION_TAKE_CONTROLS);
        llSetTimerEvent(0.5);
    }
 
    control(key id,integer level,integer edge) {
        vector impulse = <0.0,0.0,0.0>;
        if (level & CONTROL_UP)
        {
            impulse += <0,0,speed>;
        }
        if (level & CONTROL_DOWN)
        {
            impulse += <0,0,-speed>;
        }
        if (level & CONTROL_FWD)
        {
            impulse += <speed,0,0>;
        }
        if (level & CONTROL_BACK)
        {
            impulse += <-speed,0,0>;
        }
        if (level & CONTROL_LEFT)
        {
            impulse += <0,speed,0>;
        }
        if (level & CONTROL_RIGHT)
        {
            impulse += <0,-speed,0>;
        }
        llApplyImpulse((vector)impulse,1);
    }
 
    timer() {
        if (llGetAgentInfo(llGetOwner()) & AGENT_FLYING) {
            llSetForce((<0.0,0.0,9.81> * llGetMass()),0);
            jump flight_off;
        }
        llSetForce(<0.0,0.0,0.0>,0);
        @flight_off;
        llSetTimerEvent(0.5);
    }
 
    listen(integer channel, string name, key id, string message) {
        if (message == "fly on") {
            llOwnerSay("Flight engaged...");
            llRequestPermissions(llGetOwner(),4);
            llSetTimerEvent(0.5);
            return;
        }
        if (message == "fly off") {
            llOwnerSay("Flight disengaged...");
            llSetTimerEvent(0);
            llSetForce(<0.0,0.0,0.0>,0);
            llReleaseControls();
            return;
        }
        if (message == "fly faster") {
            llOwnerSay("Flying faster...");
            speed += 0.5;
            return;
        }
        if (message == "fly slower") {
            llOwnerSay("Flying slower...");
            speed -= 0.5;
            return;
        }
    }
 
    run_time_permissions(integer permissions) {
        if (permissions & PERMISSION_TAKE_CONTROLS) {
            llTakeControls(CONTROL_FWD|CONTROL_BACK|CONTROL_LEFT|CONTROL_RIGHT|CONTROL_UP|CONTROL_DOWN,1,1);
            llListen(0, "", llGetOwner(), "");
        }
    }
}