Change font size
It is currently Sat Dec 15, 2018 2:30 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 7 posts ]
Author Message
 Post subject: LSL Vehicle Script for Flight
PostPosted: Fri Feb 19, 2010 12:14 pm 
Furious Typer

Joined: Sat Jan 24, 2009 8:49 am
Posts: 64
This is a variation on previous LSL vehicle scripts by Cristy Lock, Neb, Hiro Protagonist and Kitto Flora.

A functional helicopter freebie that uses this script is available at Mocio (as Wright Plaza freebies is temporarily unavailable).

The script does not take into account the recent 'flags' introduced into the Opensim software by Revolution and may have some enhancement potential.

The SetVehicleFloatParam parameters used are basic and will be improved on with time.

Please post your improvements in this thread for others to benefit.

Thanks to Samantha Fuller for her permission to use her main rotor texture in the freebie.
{L_CODE}:
//Dene’s vehicle script for Opensim
// Kitto Flora, Hiro Protagonist, September 2009
// & christy lock, Oct – Nov 2009
// Neb, Jan 2010
// revamped by Dene Sparta, Dec/Jan 2010

integer Private = 0;    // Change to 1 to prevent others from piloting.

// Show Text / Parameters
string HoverText = "";
string ScriptNo = "Helicopter";//

key agent;

// Sit Animation
string Animation = "sit";
vector Sitpos = <.6,0,.65>;
rotation Sitrot;
string sit_message = "drive";
string not_owner_message = "You are not the owner of this vehicle";

integer tt;
vector angular_motor= <0.0,0.0,0.0>;
vector Vel;
float Velocity;

float CameraBack = -5; // Camera x offset
float CameraUp = 3; // Camera z offset

// Speed
float MaxSpeed = 30;
float SpeedStart = .01;
float speed;
float SpeedAdjust = 0.1; // 0.5 when you are more experienced at driving the helicopter

// Steering
float SteerAdjust = 0.1;
float MaxSteer = 1.0;

// Buoyancy
float Buoyancy = 1; //
float BuoyancyAdjust = .000005; //
float MaxBuoyancy = 1.000; //
float MinBuoyancy = -.9; //

// Parameter
float Parameter =0;
float ParameterStart = 0;
float ParameterAdjust = .05; // 0.2 when you are more experienced at driving the helicopter

float MaxParameter = 20;
float MinParameter = -20;

setVehicle()
{   //Car / Plane / Helicoptor
    llSetVehicleType(VEHICLE_TYPE_CAR);
    llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.2);//
    llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.80);
    llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 0.3);//
    llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.1);//
    llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1);//1.0
    llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.1);//
    llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, .1);
    llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, .05);
    llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <20, 4,75>);
    llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <.4, .4, 5>);
    llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, .3);
    llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 3);
    llSetVehicleFloatParam(VEHICLE_BUOYANCY, Buoyancy);//0.01
    llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 1 );//
    llSetVehicleFloatParam( VEHICLE_BANKING_MIX, .75 );//
    llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, .5 );//
}//end setVehicle()

ShowText()
{//    Vel = llGetVel();
//    Velocity = llVecMag(Vel);
//    llSetText(""
//    (string)HoverText + (string)ScriptNo + ", " +
//    "\n" +
//    "Speed: "+(string)speed + " m/s, " +
//  "Actual Speed = " + (string)Velocity + " m/s " +
//    "\n" +
    //"(" + (string)Vel + ")" +
    // used for troubleshooting
    // "\n" +
    // "Buoyancy " + (string)Buoyancy + ", " +
//    "Climbing Speed = " + (string)Parameter + " m/s, "
//  ,<.3,1,1>, 2.0);
}//end ShowText()

Init()
{   llSetVehicleType(VEHICLE_TYPE_CAR);
    Parameter = ParameterStart;
    speed = SpeedStart;
    llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <speed,0,Parameter>);
    angular_motor=<0,0,0>;
    llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
    llSleep(.4);
    llSetStatus(STATUS_PHYSICS, FALSE);
    ShowText();
    llClearCameraParams();
}//end Init()

default
{   state_entry()
    {   Init();
        llSetSitText(sit_message);
        llSitTarget(Sitpos, ZERO_ROTATION); 
        llSensorRemove();
        llReleaseControls();   
        llClearCameraParams();
    }// end state_entry()
   
    on_rez(integer rez)
    {llResetScript();}//on_rez(integer rez)
   
    changed(integer change)
    {   if (change & CHANGED_LINK)
        {   llSitTarget(Sitpos, ZERO_ROTATION);
            agent = llAvatarOnSitTarget();
            llSetCameraEyeOffset(<CameraBack, 0.0, CameraUp>);
            llSetCameraAtOffset(<1.0, 0.0, 2.0>);
            ShowText();
            if (agent != NULL_KEY)
            {   if( (agent != llGetOwner()) && (Private == 1) )
                {   llSay(0, not_owner_message);
                    llUnSit(agent);
                }
                else
                {   Init();
                    llLoopSound("Helicopter3",1);                 
                    setVehicle();           
                    llSetStatus(STATUS_PHYSICS, TRUE);                   
                    llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);               
                }
            }//end if (agent != NULL_KEY)
            else
            {   Init();
                llStopSound();
                llSensorRemove();
                llStopAnimation("sit");
                llReleaseControls();
            }//end else
        }//end if (change & CHANGED_LINK)
    }//end changed(integer change)
   
    touch_start(integer tn)
    {}//end touch_start(integer tn)
   
    run_time_permissions(integer perm)
    {   llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_DOWN | CONTROL_UP | CONTROL_RIGHT |
                            CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, FALSE);
        llSetStatus(STATUS_PHYSICS, TRUE);   
        llStopAnimation("sit");
        llStartAnimation(Animation);
        llSensorRepeat("Non-Entity",NULL_KEY,PASSIVE,1.0, PI_BY_TWO,1);               
    }//end run_time_permissions(integer perm)
   
    control(key id, integer level, integer edge)
    {   if(level & CONTROL_FWD)
        { //speed faster
            if(speed < MaxSpeed){speed += SpeedAdjust;}//end if(speed < MaxSpeed)
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <speed,0,Parameter>);
        }//end if(level & CONTROL_FWD)
        if(level & CONTROL_BACK)
        { //speed slower
            if(speed > -8){speed -= SpeedAdjust;}//end if(speed > -8)
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <speed,0,Parameter>);
        }//end if(level & CONTROL_BACK)
        if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
        {   // Turn right
            //angular_motor.x += 5;//
            if (angular_motor.z > -MaxSteer)
            {angular_motor.z -= SteerAdjust;}//end if (angular_motor.z > -MaxSteer)
            llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
        }
        else if (edge & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
        {   angular_motor.z = 0;
            llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
        }//end else if (edge & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
        if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
        {   // Turn left
            //angular_motor.x -= 5;
            if (angular_motor.z < MaxSteer){angular_motor.z += SteerAdjust;}//end if (angular_motor.z < MaxSteer)
            llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
        }//end if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
        else if (edge & (CONTROL_LEFT|CONTROL_ROT_LEFT))
        {   angular_motor.z = 0;
            llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
        }//end else if (edge & (CONTROL_LEFT|CONTROL_ROT_LEFT))         
        if(level & CONTROL_UP)
        {   // add features for when you press up
//            if (Buoyancy < MaxBuoyancy){Buoyancy += BuoyancyAdjust;}
//            llSetVehicleFloatParam(VEHICLE_BUOYANCY, Buoyancy);
            if (Parameter < MaxParameter)
            {Parameter += ParameterAdjust;
             llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <speed,0,Parameter>);
             // y is borked!!
            }//end if (Parameter < MaxParameter)
        }//end if(level & CONTROL_UP)
        if(level & CONTROL_DOWN)
        {   // Added feature for when you press down
            // Stops vehicle when down is pressed
            // speed=0.1;
//            if (Buoyancy > MinBuoyancy){Buoyancy -= BuoyancyAdjust;}
//            llSetVehicleFloatParam(VEHICLE_BUOYANCY, Buoyancy);// v1.15.3 
//            {Parameter = 1;}           
//            else if (Parameter > MinParameter)
            if (Parameter > MinParameter)
            {Parameter -= ParameterAdjust;
             llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <speed,0,Parameter>);// y and z are borked!!
            }//end if (Parameter > MinParameter)
        }//end if(level & CONTROL_DOWN)
    }//end control(key id, integer level, integer edge
 
    no_sensor()
    {llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <speed,0,Parameter>);}//end no_sensor
}//end default
This script is not as snazzy as Neb's racer but it flies.
Tilting the helicopter forwards and back is currently not available via rotation motor around the y axis as this seems broken at the moment. (rotates in region y axis not vehicles)

Some basic notes

This Helicopter is ideal for mega regions.

Control Basics
- Forward = up arrow key
- Backwards = down arrow key (boy this is difficult)
- Up = Page Up
- Down = Page Down

For forward / backwards & up / down, please note that the motion is sustained. i.e. releasing the key does not cause motion to slow down and stop, it continues at same speed (sustained). Use the opposite key to slow down.

Note, the Right and Left turning is NOT sustained & stops when right/left keys are released (otherwise would be hard to drive).

To sit properly and reliably in the helicopter and have a nice view forward, right click on the invisible root prim under the helicopter and select 'drive'.

Feel free to modify the helicopter and script.

Would be great if your enhancements were made available to everyone by posting here and giving freebies.

Dene


Top
 Profile  
 
 Post subject: Re: LSL Vehicle Script for Flight
PostPosted: Mon Feb 22, 2010 6:05 pm 
Furious Typer

Joined: Sat Jan 24, 2009 8:49 am
Posts: 64
Hi All,

Update

The freebie Helicopter is available on Wright Plaza region (see "Dene's Design" area) and also on a region called Mocio (the freebie is near the roller coaster 'instruction board').

Whilst your at Mocio, you are welcome to have a ride on the 3 roller coaster rides plus the 'Loop the Loop' ride there. Also, there is Kharmen's fabulous trains to ride on in the adjacent region of Meue.

Tip
Opensim (or ODE engine or more precisely) currently does not like changes to prim properties or LSL vehicle scripts. And you will often find yourself and your vehicle hundreds of metres in the air or worse at -10mil meters (yes that's a negative 10 million metres) underground.

The workaround.

In edit object mode, 'Object' tab, lift the object off any surface or ground, tick the 'Physical' box and leave for about 10 seconds (more if it has lots of prims then longer). Then tick the 'Phantom' box and then un-tick it. The object will probably move. Un-tick the 'Physical' box and usually you are ready to fly / drive. Whilst this is a pain, the alternative is to restart your region which is time consuming.

Additionally, it is best to build thick walls around you region or mega region AND above AND below your land / water to try to contain your wild creation. I still go through 10m thick steel walls. (You can always put a clear or nice texture on the walls if you don't like the plywood walls aesthetics.! hehe)

Have Fun.

Dene


Last edited by Dene Sparta on Fri Mar 05, 2010 11:54 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: LSL Vehicle Script for Flight
PostPosted: Wed Feb 24, 2010 2:26 am 
That's amazing powered flight for OSgrid...must be a first!..oh and i loved your monorail ride too!


Top
  
 
 Post subject: Re: LSL Vehicle Script for Flight
PostPosted: Mon Mar 01, 2010 8:11 pm 

Joined: Tue Apr 14, 2009 6:34 am
Posts: 39
Ohhh I really going to have to give this a try on my 25 region mega

Soon as I get out of bed I will head over to find the chopper

Thank you very much for posting this Dene, much appreciated :)


Top
 Profile  
 
 Post subject: Re: LSL Vehicle Script for Flight
PostPosted: Fri Sep 16, 2011 7:23 am 

Joined: Fri Sep 16, 2011 7:22 am
Posts: 2
Hi guys! Thanks for sharing the script :D

However me beeing a total noob I do have some problems. I cant get the UP/DOWN movement to work. Forward, backward, left and right works fine though. Any suggestions? :)


Top
 Profile  
 
 Post subject: Re: LSL Vehicle Script for Flight
PostPosted: Sat Sep 17, 2011 1:02 am 
As far as I know this script got broke..I have a helecopter at my shop that behaves the same way. Neb fixed the script once, but not sure its not broken again. You can maybe find his flying machine at OKC sandbox to copy and try. Otherwise there is this.

http://forums.osgrid.org/viewtopic.php?f=5&t=3336


Top
  
 
 Post subject: Re: LSL Vehicle Script for Flight
PostPosted: Mon Sep 19, 2011 6:50 am 

Joined: Fri Sep 16, 2011 7:22 am
Posts: 2
Sarah Kline {L_WROTE}:
As far as I know this script got broke..I have a helecopter at my shop that behaves the same way. Neb fixed the script once, but not sure its not broken again. You can maybe find his flying machine at OKC sandbox to copy and try. Otherwise there is this.

http://forums.osgrid.org/viewtopic.php?f=5&t=3336


Thanks I'll try that. =)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 7 posts ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net