Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Vehicles A_flight_script_with_more_realistic  

A_flight_script_with_more_realistic

My more elaborate airplane and bird scripts are also available free in world, but I suggest that this is the place to start. This scrpt is public domain "Copyleft!". My others are distributed under GNU Free Public Licenses, so only the ideas and short sections of script should be used in proprietary flight scripts, not long sections verbatim. Direct derivatives of the others should remain open source.

I am anxious for others to use my new methods. I realize that most sl residents don't have strong backgrounds in physical analysis and modeling, numerical methods and real time programming, so I have tried to make this a script that others will be able to use as a starting place and adapt to their own requirements. One can look at the other scripts when ready to add more details and features.

Category: Vehicles
By : Fritz Kakapo
Created: 2010-12-28 Edited: 2010-12-28
Worlds: Second Life

the Zip file

Download all files for A_flight_script_with_more_realistic
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. A_flight_script_with_more_realistic_1.lsl
Get file # 2. A_flight_script_with_more_realistic_2.lsl
1 //====================================================================================================================================
2 // PIETENPOL AIR CAMPER FLIGHT SCRIPT MK1, with F. t. C.'s extensive changes
3 //
4 // Portions of this script are influenced by or based on work from Alex Linden, Cubey Terra, Eoin Widget, Kerian Bunin, Ronald Krugman
5 // Script by Ezekiel Bailly 2005-2008
6 // New, more physical, flight behavior and other changes by Fritz t. Cat (Fritz Kakapo), April--May 2010.
7 // Copyleft!
8 //--------------------------------------------------------------------------------------------------------------------------------------
9 // Some of Fritz's changes:
10 // Making it act like an airplane, maybe even like a Model A engined Air Camper,
11 // but keeping it simple and as compatible as I can with what other sl flight scripters are doing.
12 // Explaining how this new script relates to the simplified physics of airplanes.
13 // Separated aileron and rudder controls. (The variables controlling the prim angles were already separate.)
14 // Some improvements in response time.
15 // Pulling loose wires. When I was a student, they used to send me up to trace signal cables and remove them if open.
16 // Trying to make it easier for the next person (or robot?) who works on it.
17 // Took out HUD control, for simplicity and efficiency. (Each listen puts a lot of load on the server, or used to at least.)
18 // More concise, clearer and more efficient code. Tables of if statements could be replaced by formulas, for example.
19 // Formatting. I prefer less blank lines, dashes instead. More consistent and standard indenting.
20 // Deleting long obsolete comments, better variable names.
21 //
22 // Wikipedia says stall speed 35 mph, top 100 mph, rate of climb 500 ft/min (152 m/min).
23 // It lists the Model as as 40 horsepower (30 kW), and the Camper loaded weight as 995 lb (452 kg).
24 // Because of sl limitattions, I have modeled that at half speed.
25 // The stall here is not realistic and is too slow, to keep it easy to fly and simple.
26 // Too slow can be fixed by increasing LINEAR_FRICTION_TIMESCALE.z to decrease lift.
27 // The stall is too gentle because of the approximation that the lift is proportional to the angle of incidence
28 // times the square of the speed, which breaks down in a stall because of boundary layer separation.
29 // It would be somewhat improved by making the linear friction increase (LINEAR_FRICTION_TIMESCALE decrease) with speed,
30 // but this is a simple script, and it is easier to fly without that.
31 //
32 // Come the revolution, there'll be no more flying level, just the same, with the wings vertical!
33 // Come the revolution, airplanes will turn toward the low wing, even when up side down!
34 //======================================================================================================================================
35 //
36 //
37 // *AC control flags that we set later (It won't do logic in the initialization of variables.)
38 integer gAngularControls;
39 // *AC we may keep track of angular history for more responsive turns
40 integer gOldAngularLevel;
41 // Landing Gear Weight on Wheels-Collision Integer
42 integer onground = TRUE;
43 // THROTTLE (SPEED) Sensitive Declarations
44 // Thrust variables:
45 // thrust = forward * thrust_multiplier
46 // Edit the maxThrottle and thrustMultiplier to determine max speed.
47 integer forward = 0; // this changes when pilot uses throttle controls
48 integer maxThrottle = 5; // Number of "clicks" in throttle control. Arbitrary, really.
49 float thrustMultiplier = 11.; // Amount thrust increases per click.
50 //
51 // Lift and speed
52 //float cruiseSpeed = 19.0; // knots, speed at which plane achieves full lift, knots!
53 float speed = 0.; // speed in m/s
54 float requested_timer_interval = 0.5; // timer call requested rate, it can be much slower
55 integer sit = FALSE; // pilot sitting
56 integer ignition = FALSE; // engine running, object physical
57 //
58 // Control Surface Motion Declarations
59 string last_aileron_direction;
60 string cur_aileron_direction;
61 //
62 string last_elevator_direction;
63 string cur_elevator_direction;
64 string last_rudder_direction;
65 string cur_rudder_direction;
66 //
67 // CAMERA DECLARATIONS
68 list drive_cam =
69 [
70 CAMERA_ACTIVE, TRUE,
73 CAMERA_DISTANCE, 10.0,//3.0,
74 PITCH" title="View Definition" class="tooltip">CAMERA_PITCH, 10.0,
75 // CAMERA_FOCUS,
76 CAMERA_FOCUS_LAG, 0.05,
77 CAMERA_FOCUS_LOCKED, FALSE,
78 CAMERA_FOCUS_THRESHOLD, 0.0,
80 CAMERA_POSITION_LAG, 0.3,
81 CAMERA_POSITION_LOCKED, FALSE,
82 CAMERA_POSITION_THRESHOLD, 0.0,
83 //
84 CAMERA_FOCUS_OFFSET,<0,0,1>//<0,0,1>
85 ];
86 integer camon = FALSE;
87 integer camPermed;
88 //
89 key pilot = NULL_KEY;
90 vector angular_motor; //
91 vector global_vel; // velocity in the sim coordinate system
92 vector local_vel; // velocity in the coordinate system pointed as the airplane
93 integer thrustPercent = 0;
94 float ANGULAR_MOTOR_TIMESCALE_0 = 4.; // strength of angular motor and angular damping
95 float VERTICAL_ATTRACTION_TIMESCALE_0 = 17.;
96 //--------------------------------------------------------------------------------------------------------------------------
97 integer HUDon = TRUE; //"Heads Up Display" variables
98 string HUDtext = "";
99 vector HUDcolor;
100 //==========================================================================================================================
101 //
102 init()
103 {
104 llListen(0, "", llGetOwner(), "" );
105 //
106 llSetCameraEyeOffset( < -12, 0., 3.5 > ); // Position of camera, relative to parent.
107 llSetCameraAtOffset( <0, 0, 1.9 > ); // Point to look at, relative to parent.
108 //
109 llSetSitText( "AirCamper" ); // Text that appears in pie menu when you sit
110 //
111 llCollisionSound( "", 0.0 ); // Remove the annoying thump sound from collisions
112 //
113 //SET VEHICLE PARAMETERS -- See www.secondlife.com/badgeo for an explanation
115 //
116 // angular deflection, fin and rudder
119 //
120 // linear deflection
121 llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0. ); // fuselage lift, both pitch and yaw cause lift
122 llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 1000. ); // but we use LINEAR_FRICTION instead.
123 //
124 // angular friction
125 llSetVehicleVectorParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, < 1.5, 3., 6. > ); // Caused by drag of extremities.
126 //
127 // linear friction
129 // This is the all-important trick to get the physics engine to handle the wing lift.
130 // The x and y components contribute to parasite drag and to fuselage lift.
131 // I have a note card explaining how the dependence of both lift and drag on pitch angle
132 // are accurately and efficiently modeled by this parameter.
133 // (To get a realistic depenence of lift and drag on speed, this parameter should decrease with speed.)
134 //
135 llSetVehicleVectorParam( VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0> ); // Start with the Model A off.
136 //
137 llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 24. ); // loose control to feel like air
138 llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 10. ); // 20 times the timer interval.
139 // If this is too long, it gets lost between sims more often. If it is too short, it falls in busy sims.
140 //
141 // angular motor
142 llSetVehicleVectorParam( VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0> ); // control surfaces
143 //
144 llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, ANGULAR_MOTOR_TIMESCALE_0/5. ); // strength of " and angular damping
145 //
146 llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 3. ); // can be refreshed in timer or not
147 //
148 // hover
149 llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, 0. ); // useful for sea planes
150 llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY, 0. ); // or for taking off from bare ground
152 //
153 // vertical attractor
154 // This tends to keep the airplane right side up.
155 // More technically, it gives it dynamic stability against spiral dive.
156 // In rl airplanes, this stability is provided largely by dihedral and by
157 // the vertical distance between the aerodynamic center and the center of gravity.
158 // This vertical attractor is less realistic but simpler than the dihedral approximation I use in Li'l Stinker.
160 llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, VERTICAL_ATTRACTION_TIMESCALE_0 );
161 // The /10. is to fix leaning over on ground, probably caused by the lack of a good sit animation.
162 //
163 // banking I don't know much what this does yet, so I am not using it.
164 // Used in a straightforward way, it is partly responsible for the
165 // un-airplanelike behavior of other sl airplanes.
166 // It was obviously not introduced with airplanes in mind (at least not in a rational mind).
167 // (I tried reversing it when up side down, but did not understand the result.)
170 //
171 // Falls half as fast, as though the space and speed were twice as big,
172 // to deal with the small size of sims and the slowness of handoffs between sims.
173 llSetVehicleFloatParam( VEHICLE_BUOYANCY, 0.5 ); // This and must be a constant (for any flight mode).
174 //
175 // default rotation of local frame
176 llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME, <0,0,0,1> ); // A noop, I think.
177 //
178 // remove these flags
186 //-----------------------------------------------------------------------------------------------------------------
187 //
189 //
190 refreshHUD();
191 //
192 llSay(0, "Cogito ergo sum." ); // "I think therefore I am.", Descartes. Variant on "Hello world!"
193 //
194 } // End init.
195 //
196 //-----------------------------------------------------------------------------------------------------------------------------------
197 //
198 refreshHUD() // from the VICE test airplane
199 {
200 if( !sit )
201 {
202 HUDtext="Take a copy, or buy for l$ 0. \n Full permissions,
203 Revolutionary flight script.
204 Public domain, no restrictions on use.
205 Open the airplane as a box to get the documentation.";
206 HUDcolor = < 0.2, 0.4, 1. >;
207 jump GOTO;
208 }
209 //
210 if( !HUDon )
211 {
212 HUDtext="";
213 jump GOTO;
214 }
215 //
216 HUDtext = "Airpeed: " + (string)llFloor( (local_vel.x + 0.5) ) + " m/s"
217 + " = "+(string)llFloor( ( local_vel.x*1.94 + 0.5 ) ) + " kts."
218 + " = "+(string)llFloor( ( local_vel.x * 100./2.54/12./5280. *60.*60. + 0.5 ) ) + " mi./hr."
219 + "\n " +" = "+(string)llFloor( local_vel.x *100. /2.54/12. /5280. *60.*60. * 2. + 0.5 ) + " scaled mi./hr."
220 + "\n Rate of climb: " + " = " +
221 (string)( llFloor( global_vel.z *100. /2.54 /12. *60. * 2. /10. + 0.5 ) * 10 ) + " scaled foot/min."
222 + "\n " +
223 "Throttle: " + (string)thrustPercent + "%";
224 //
225 HUDcolor = < 1.0, 1.0, 1.0 >; // white when combat is disabled
226 //
227 @GOTO;
228 //
229 llSetText( "", HUDcolor, 1.0);
230 //llSetText(HUDtext+"\n \n \n \n \n \n \n ", HUDcolor, 1.0);
231 //
232 llMessageLinked( 2, 333, (string)HUDcolor, NULL_KEY );
233 llMessageLinked( 2, 137, HUDtext+"\n \n \n ", NULL_KEY );
234 //
235 } // End refreshHUD().
236 //
237 //-----------------------------------------------------------------------------------------------------------------------------------
238 //
239 default
240 {
242 {
243 init();
244 }
245 //
246 //----------------------------------------------------------------------------------------------------------------------
247 on_rez(integer num)
248 {
249 llOwnerSay("Welcome to the Pietenpol Air Camper, type 'help' for the manual.");
250 llOwnerSay("These controls can be typed in chat:");
251 llOwnerSay("Start, stop the engine: 'contact' , 'cutoff' ");
252 //llOwnerSay("Seat position: 'seatup' 'seatdown' (You will need to Re-sit) ");
253 llOwnerSay("'smoke' turns colored smoke off and on.");
254 //
255 llOwnerSay(" ");
256 llOwnerSay( "The arrow keys or a, d work the ailerons.");
257 llOwnerSay( "Shift arrow or shift a, d controls the rudder." );
258 llOwnerSay( "Up, down arrow or s, w controls the elevator, as usual." );
259 llOwnerSay( "Page up, down or e, c changes the throttle, as usual." );
260 llOwnerSay( "For a good turn, start the turn with the ailerons, then continue it with the rudder and elevator." );
261 llOwnerSay( "But the elevator and ailerons don't work at the same time as the rudder, sorry." );
262 llOwnerSay( "Use full throttle for take off." );
263 //
264 init();
265 }
266 //
267 // DETECT AV SITTING/UNSITTING AND TAKE CONTROLS
268 //-----------------------------------------------------------------------------------------------------------------------------------
269 changed( integer change )
270 {
271 //
272 if( change & CHANGED_LINK )
273 {
274 pilot = llAvatarOnSitTarget();
275 //
276 if( pilot )
277 {
278 if( pilot != llGetOwner() )
279 //if( FALSE )
280 {
281 // only the owner can use this vehicle
282 llWhisper(0,
283 "Please take a copy of this airplane and fly your own copy.
284 (If it is not set \"free to copy\" or \"for sale 0 l$\" contact the owner or the creator.)
285 You aren't the owner -- only the owner can fly this plane.");
286 llUnSit( pilot );
287 //llPushObject(pilot, <0,0,10>, ZERO_VECTOR, FALSE);
288 }
289 else
290 { // Pilot sits on vehicle
291
293 llSetTimerEvent( requested_timer_interval );
294 llMessageLinked( LINK_SET, 0, "seated", "" );
295 llMessageLinked( LINK_ALL_CHILDREN , 0, "CONTROLS_FLYING", NULL_KEY );
296 sit = TRUE;
297 forward = 0;
298 thrustPercent = 0;
300 //
301 llSay(0, "Seated." );
302 }
303 } // End pilot.
304 //
305 else if( sit )
306 // When changed is called with flying and CHANGED_LINK, it is usually that the avatar is getting up.
307 {
308 // Pilot is getting up.
309 //
311 llSetTimerEvent( 0 );
312 llMessageLinked( LINK_SET, 0, "unseated", "" );
315 //
317 sit = FALSE;
318 //
319 llSay(0, "Unseated." );
320 //
321 //llPushObject( pilot, <0,0, 10. >, ZERO_VECTOR, FALSE ); << This goes in the pilot seat script.
322 //llSetStatus(STATUS_PHANTOM, TRUE); // It falls through the floor.
323 //llSleep(4.0);
324 //llSetStatus(STATUS_PHANTOM, FALSE );
325 //
326 } // End sit.
327 else llSay(0, "??" ); // for debugging
328 }
329 refreshHUD();
330 //
331 } // End changed.
332 //
333 //------------------------------------------------------------------------------------------------------------------------
334 //CHECK PERMISSIONS AND TAKE CONTROLS
336 {
338 {
342 , TRUE, FALSE);
343 }
344 } // End run_time_permissions.
345 //
346 //----------------------------------------------------------------------------------------
347 //
348 listen( integer channel, string name, key id, string message )
349 {
350 //Aircraft Start Watcher
351 //if( (message == "contact") && (ignition == FALSE) )
352 if( message == "contact" )
353 {
354 ignition = TRUE;
355 llOwnerSay( "Starting Engine" );
357 llMessageLinked( LINK_SET, 0, "start", NULL_KEY );
358 //thrustPercent = (integer) llFloor( (float)(forward+1) / (float)maxThrottle * 100. + 0.5 );
359 }
360 //else if( ( message == "cutoff" ) && (ignition == TRUE) )
361 else if( message == "cutoff" )
362 {
363 ignition = FALSE;
364 llOwnerSay( "Engine Stop" );
366 llMessageLinked( LINK_SET, 0, "stop", NULL_KEY );
367 }
368 //
369 else if( (message=="c") && (camon==FALSE) ) // No tested.
370 {
371 llSetCameraParams(drive_cam);
372 camon=TRUE;
373 llOwnerSay("Dynamic Camera on");
374 }
375
376 else if( (message=="c") && (camon==TRUE) )
377 {
379 camon=FALSE;
380 llOwnerSay("Dynamic Camera off");
381 }
382 else if( message == "smoke" )
383 // Added by FtC, because I can't feel the acceleration in the seat of my pants.
384 {
385 llMessageLinked( LINK_SET, 0, "smoke", NULL_KEY );
386 // (The smoke script starts and stops the smoke with the engine but remembers this command.)
387 }
388 } // End listen.
389 //
390 //----------------------------------------------------------------------------------------
391 //
392 //FLIGHT CONTROLS
393 control( key id, integer levels, integer edge )
394 {
395 // OBC DECLARATIONS
396 integer throttle_up = CONTROL_UP;
397 integer throttle_down = CONTROL_DOWN;
398 //
399 //
400 if( (levels & (throttle_up+throttle_down)) && ignition )
401 {
402 ////////////// THROTTLE INCREASE ////////////////
403 if( levels & throttle_up )
404 {
405 if( forward < maxThrottle-1 )
406 {
407 forward += 1;
408 }
409 }
410 //
411 ////////////// THROTTLE DECREASE ////////////////
412 else if( levels & throttle_down )
413 {
414 if( forward > 0 )
415 {
416 forward -= 1;
417 }
418 }
419 llSetVehicleVectorParam( VEHICLE_LINEAR_MOTOR_DIRECTION, < forward * thrustMultiplier, 0, 0 > );
420 //
421 // Calculate percent of max throttle and send to child prims as link message
422 thrustPercent = (integer) llFloor( (float)(forward+1) / (float)maxThrottle * 100. + 0.5 );
423 //
424 llMessageLinked( LINK_SET, thrustPercent, "throttle", "" );
425 //
426 llOwnerSay( "Throttle at " + (string)thrustPercent + " %" );
427 //
428 refreshHUD();
429 //
430 llSleep( 0.15 ); // crappy kludge // This must be to avoid multiple clicks.
431 }
432 //
433 // only change angular motor if the angular levels have changed
434 //
435 if( (edge & gOldAngularLevel) || (levels & gAngularControls) )
436 {
437 // This is not fly by wire or fly by light, so the controls work when the pilot is seated.
438 // The fact that they still have some effect at zero speed is an unrealistic convenience.
439 // By the standard simple approximation, both lift and control surface effectiveness are proportional
440 // to the square of the speed. This is a compromise between that and flying ease.
441 //
442 angular_motor = <0,0,0>;
443 cur_aileron_direction = "AILERON_NEUTRAL"; // Start neutral.
444 cur_elevator_direction = "ELEVATOR_NEUTRAL";
445 cur_rudder_direction = "RUDDER_NEUTRAL";
446 //
447 // ailerons
448 if( levels & CONTROL_ROT_RIGHT )
449 {
450 cur_aileron_direction = "AILERON_RIGHT";
451 angular_motor.x += 2.5 * (0.5 + speed/10.);
452 }
453 //
454 if( levels & CONTROL_ROT_LEFT )
455 {
456 cur_aileron_direction = "AILERON_LEFT";
457 angular_motor.x -= 2.5 * (0.5 + speed/10.);
458 }
459 //
460 // rudder
461 if( levels & CONTROL_RIGHT )
462 {
463 cur_rudder_direction = "RUDDER_RIGHT";
464 angular_motor.z -= 1.3 * (0.7 + speed/10.);
465 }
466 //
467 if( levels & CONTROL_LEFT )
468 {
469 cur_rudder_direction = "RUDDER_LEFT";
470 angular_motor.z += 1.3 * (0.7 + speed/10.);
471 }
472 //
473 // elevator
474 if( levels & CONTROL_BACK )
475 {
476 // add pitch component ==> causes vehicle lift nose (in local frame)
477 cur_elevator_direction = "ELEVATOR_UP";
478 angular_motor.y -= 1.2 * (0.7 + speed/10.);
479 }
480 if( levels & CONTROL_FWD )
481 {
482 cur_elevator_direction = "ELEVATOR_DOWN";
483 angular_motor.y += 1.2 * (0.7 + speed/10.);
484 }
486 //
487 // These are moved from timer to reduce the delay.
488 //
489 if( cur_aileron_direction != last_aileron_direction )
490 {
491 llMessageLinked( LINK_ALL_CHILDREN , 0, cur_aileron_direction, NULL_KEY );
492 last_aileron_direction = cur_aileron_direction;
493 }
494 if( cur_elevator_direction != last_elevator_direction )
495 {
496 llMessageLinked( LINK_ALL_CHILDREN , 0, cur_elevator_direction, NULL_KEY );
497 last_elevator_direction = cur_elevator_direction;
498 }
499 if( cur_rudder_direction != last_rudder_direction )
500 {
501 llMessageLinked( LINK_ALL_CHILDREN , 0, cur_rudder_direction, NULL_KEY );
502 last_rudder_direction = cur_rudder_direction;
503 }
504 //
505 } // End angular controls.
506 // store the angular levels history for the next control callback
507 gOldAngularLevel = levels & gAngularControls;
508 //
509 } // End control.
510 //
511 //----------------------------------------------------------------------------------------------------------------------------
512 // LAND COLLISION FILTER FOR turn BEHAVIOR // Used now only for unrealistic convenience.
513 //
514 collision_start(integer num_detected) {
515 //llOwnerSay( "Down." );
516 llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, ANGULAR_MOTOR_TIMESCALE_0/10. ); // More torque needed on ground.
517 llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, VERTICAL_ATTRACTION_TIMESCALE_0 / 20. );
518 // The wheel keep us right side up.
519 onground = TRUE;
520 }
521 collision_end(integer num_detected){
522 //llOwnerSay( "Up." );
523 //llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, ANGULAR_MOTOR_TIMESCALE_0 ); // Less torque needed in air.
524 onground = FALSE;
525 }
526 land_collision_start(vector pos) {
527 //llOwnerSay( "Down." );
528 llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, ANGULAR_MOTOR_TIMESCALE_0/10. ); // More torque needed on ground.
529 llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, VERTICAL_ATTRACTION_TIMESCALE_0 / 20. );
530 // The wheel keep us right side up.
531 onground = TRUE;
532 }
533 land_collision_end(vector pos) {
534 //llOwnerSay( "Up." );
535 //llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, ANGULAR_MOTOR_TIMESCALE_0 ); // Less torque needed in air.
536 onground = FALSE;
537 }
538 //----------------------------------------------------------------------------------------
539 //Aircraft Start Watcher // I took this out for efficiency and simplicity.
540 //link_message( integer send, integer num, string msg, key id )
541 //{
542 // if(( msg == "contact" ) && (ignition == FALSE))
543 // {
544 // ignition= TRUE;
545 // llOwnerSay("Starting Engine");
547 // }
548 // else if(( msg == "cutoff" ) && (ignition == TRUE) )
549 // {
550 // ignition = FALSE;
551 // llOwnerSay("Engine Stop");
553 // }
554 //}
555 //------------------------------------------------------------------------------------------------------------------------
556 //
557 timer()
558 {
559 global_vel = llGetVel();
560 speed = llVecMag( global_vel );
561 float speed_kt = speed * 1.94384449; // Calculate speed in knots.
562 local_vel = global_vel / llGetRot(); // to coordinate frame alligned with body
563 //
564 llSetVehicleVectorParam( VEHICLE_LINEAR_MOTOR_DIRECTION, < forward*thrustMultiplier, 0, 0 > ); // Keep engine running.
565 llSetVehicleVectorParam( VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor ); // Keeps friction constant.
566 //
567 if( onground )
568 ;
569 //llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, VERTICAL_ATTRACTION_TIMESCALE_0 / 10. );
570 else
571 llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, ANGULAR_MOTOR_TIMESCALE_0 / (1.5 + 0.5*speed/10.) );
572 // More torque needed at higher speed.
573 llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, VERTICAL_ATTRACTION_TIMESCALE_0 / (1.5 + 0.5*speed/10.) );
574 // Dihedral and wing sweep are more effective at higher speed.
575 //
576 refreshHUD();
577 //
578 } // End timer.
579 } // End default.
580 //
581 //=======================================================================================
582 //
583
584

A_flight_script_with_more_realistic

To fly, this also requires the pilot seat script, also in the root prim.

Category: Vehicles
By : Fritz Kakapo
Created: 2010-12-28 Edited: 2010-12-28
Worlds: Second Life

1 //string sit_anim = "vseat"; This sit annimation didn't work. The pilot scrapes on the ground too badly.
2 key pilot;
3 //
4 default
5 {
6 // Vario-position Pilot Seat for Pietenpol Air Camper
7 // Ezekiel Bailly
8 // CopyLeft
9 // Current Limitation is that Pilot needs to standup and then re-sit to effect change
10 //
12 {
13 pilot = NULL_KEY;
14 llListen( 0, "", llGetOwner(), "" );
15 llSitTarget( < 0.3, 0.0, 0.40 >, llEuler2Rot(<0,0,0>) ); // Start in up position.
16 }
17 //
18 changed(integer change)
19 {
20 key sitting = llAvatarOnSitTarget();
21 if( change & CHANGED_LINK )
22 {
23 if( sitting != NULL_KEY && pilot == NULL_KEY )
24 {
25 if( sitting = llGetOwner() )
26 {
27 pilot = sitting;
28 //llMessageLinked( 1, 0, "llWhisper", "/me pilotr " + llKey2Name(sitting) );
29 //if(sit_anim != "")
30 //{
32 //}
33 }
34 }
35 else if( sitting == NULL_KEY && pilot != NULL_KEY )
36 {
38 {
40 llSetStatus(STATUS_PHANTOM, TRUE);
41 //llStopAnimation(sit_anim);
42 llSleep(2.0);
43 llSetStatus(STATUS_PHANTOM, FALSE);
44 }
45 pilot = NULL_KEY;
46 llMessageLinked( LINK_SET, 0, "pilot", NULL_KEY );
47 }
48 }
49 }
50 //
52 {
54 }
55 //
56 listen(integer chan, string name, key id, string msg)
57 {
58 if(msg == "seatdown")
59 {
60 llSitTarget( < 0.3,0.0,0.35 >, llEuler2Rot(<0,0,0>) );
61 llSay(0, "Seat Position: Down");
62 }
63 else if( msg == "seatup" )
64 {
65 llSitTarget( < 0.3, 0.0, 0.40 >, llEuler2Rot(<0,0,0>) );
66 llSay(0, "Seat Position: Up");
67 }
68 else if(msg == "help")
69 {
70 llGiveInventory( id, "Pietenpol manual" );
71 }
72 }
73 // This annimation puts the avatar too high, so the sit position has to be too low,
74 // so the airplane is pushed off the ground.
75 //
77 //{
79 // llStartAnimation(sit_anim);
80 // }
81 //}
82 }
83 //============================================================================================================
84 //

Back to the Best Free Tools in Second Life and OpenSim.