Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //OpenSim Helicopter script
- //Kayaker Magic aka Mike Kayaker
- // June 2012
- // This script is open source, have fun!
- // WARNING: This script takes advantage of KNOWN BUGS in OpenSim to
- // get the vehicle to work reliably.
- // Written from the ground up for OpenSim, won't work on SL!
- // It has been tested to work in OS 0.7.1.1 & 0.7.4.0 and will fail when
- // the bugs are fixed in later versions!
- // I make no attempt to set the camera, you can usually cam around behind
- // yourself with CTRL-ALT-mouse and get it to stay there while flying.
- // To use: Put this script in the root prim of a helicopter
- // putting it in a 2x1x0.01 box makes a nice magic carpet for starters.
- // Sit on the vehicle an then:
- // up-arrow pitches the helicopter nose down so the prop starts pulling it foreword
- // down-arrow pitches the helicopter nose up so the prop pulls you backward.
- // left-arrow rotates the helicopter left
- // right-arrow rotates the helicopter right
- // Page-up page-down moves the helicopter smoothly up and down in one meter increments.
- // (tap and release page-up/down multiple times to rise fast)
- float gHeight; //global height
- string sitanim="sit_ground"; //how to sit on the vehicle
- default
- {
- state_entry()
- {
- llSetSitText("Fly");
- llCollisionSound("",0.0);
- llSitTarget(<-0.3, 0.0, 0.8>, ZERO_ROTATION);
- vector pos=llGetPos(); //position to initialize global hover height
- gHeight=pos.z;
- llSetRot(ZERO_ROTATION); //level it off on a reset
- llSetVehicleType(VEHICLE_TYPE_BALLOON); //start with a simple vehicle type
- // linear friction high so we don't run into the sim boundary so soon
- llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <3,3,3> );
- // uniform angular friction
- llSetVehicleFloatParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, 20 );
- //BUG NUMBER ONE (mantis issue 6040)
- // linear motor is constantly straining up against the linear motor bug
- // so when you tilt the vehicle, it moves horizontally
- llSetVehicleVectorParam( VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 20> );
- llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 5 );
- llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 1000 );
- // agular motor, apply fast, decays slow 'cause I stop it on button up
- llSetVehicleVectorParam( VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0> );
- llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 3 );
- llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 100 );
- // hover is used to move the vehicle up and down
- // because the linear motor won't work in Z (bug number one)
- llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT,gHeight);
- llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY, 1 );
- llSetVehicleFloatParam( VEHICLE_HOVER_TIMESCALE, 3 );
- llSetVehicleFloatParam( VEHICLE_BUOYANCY, 1 ); //should be on, but make sure
- // no linear deflection
- // llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0 );
- // llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 5 );
- // no angular deflection
- // llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0 );
- // llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 5 );
- // vertical attractor helps slow me down, since tilt controls speed
- llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, .99 );
- llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 3 );
- // no banking
- // llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 1 );
- // llSetVehicleFloatParam( VEHICLE_BANKING_MIX, 0.7 );
- // llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, 5 );
- // default rotation of local frame
- // llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME, <0, 0, 0, 1> );
- // remove all flags but hover global height
- llRemoveVehicleFlags(
- VEHICLE_FLAG_NO_DEFLECTION_UP
- | VEHICLE_FLAG_HOVER_WATER_ONLY
- | VEHICLE_FLAG_LIMIT_ROLL_ONLY
- | VEHICLE_FLAG_HOVER_TERRAIN_ONLY
- // | VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT
- | VEHICLE_FLAG_HOVER_UP_ONLY
- | VEHICLE_FLAG_LIMIT_MOTOR_UP );
- llSetVehicleFlags(VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT);
- }
- on_rez(integer pram)
- {
- llSetPos(llGetPos()+<0,0,1.5>); //jump up to clear the ground a little bit
- llResetScript();
- }
- changed(integer change)
- {
- if (change & CHANGED_LINK)
- {
- if (llAvatarOnSitTarget()!=NULL_KEY)
- {
- llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 20>);
- llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0>);
- llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
- //bounce up a bit to get away from obstacles
- gHeight+=2.0;
- llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT,gHeight);
- }
- else
- {
- //BUG NUMBER TWO (mantis issue 5964)
- //turning physics off does not always work, so try to set all the
- //vehicle parameters to zero so it will not run away
- llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0>);
- llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0>);
- llSetStatus(STATUS_PHYSICS, FALSE); //try to turn it off, might help
- //OPENSIM FEATURE: You are allowed to call llSetRot on a
- //physical object. I want to set the tilt to zero to make sure
- //the vehicle stops moving horizontally
- vector angles=llRot2Euler(llGetRot());
- llSetRot(llEuler2Rot(<0,0,angles.z>));
- llReleaseControls();
- llStopAnimation(sitanim);
- }
- }
- }
- run_time_permissions(integer perm)
- {
- if (perm)
- {
- if (perm & PERMISSION_TRIGGER_ANIMATION)
- {
- llStopAnimation("sit");
- llStartAnimation(sitanim);
- llSetStatus(STATUS_PHYSICS, TRUE);
- gHeight+=2.0; //bounce up a bit to get away from obstacles
- llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT,gHeight);
- }
- if (perm & PERMISSION_TAKE_CONTROLS)
- llTakeControls(
- CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT |
- CONTROL_BACK | CONTROL_FWD | CONTROL_UP | CONTROL_DOWN,
- TRUE, FALSE);
- }
- }
- control(key id, integer level, integer edge)
- {
- vector angmotor=<0,0,0>;
- integer angflag=0;
- if (level & edge & CONTROL_UP) //page up pressed
- {
- gHeight += 1.0;
- llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT,gHeight);
- }
- if ( level & edge & CONTROL_DOWN) //page down pressed
- {
- gHeight -= 1.0;
- if (gHeight<llGround(ZERO_VECTOR)+2.0) gHeight=llGround(ZERO_VECTOR)+2.0;
- llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT,gHeight);
- }
- if ( level & edge & CONTROL_FWD) //foreward button pressed
- {
- angmotor.y = 2;
- angflag = 1;
- }
- if (~level & edge & CONTROL_FWD) //foreward button released
- angflag = 1;
- if ( level & edge & CONTROL_BACK) //back button pressed
- {
- angmotor.y = -2;
- angflag = 1;
- }
- if (~level & edge & CONTROL_BACK) //back button released
- angflag = 1;
- if( level & edge & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
- {
- angmotor.z = -1;
- angmotor.x = .5;
- angflag = 1;
- }
- if(~level & edge & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
- angflag = 1; //default is to go to zero
- if( level & edge & (CONTROL_LEFT|CONTROL_ROT_LEFT))
- {
- angmotor.z = 1;
- angmotor.x = -0.5;
- angflag = 1;
- }
- if(~level & edge & (CONTROL_LEFT|CONTROL_ROT_LEFT))
- angflag = 1;
- //BUG NUMBER THREE (mantis issue 6039)
- //The angular motor rotates around the global region axis
- //to make the vehicle pitch around it's local axis
- //I had do multiply the angular motor by llGetRot()
- if (angflag)
- llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angmotor*llGetRot());
- } //control
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement