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
vehicle Air Camper  

Air Camper

DESCRIPTION: []::AIR CAMPER FLIGHT SCRIPT

Category: vehicle
By : Ezekiel Bailly
Created: 2014-04-19 Edited: 2014-04-19
Worlds: Second Life

the Zip file

Download all files for Air Camper
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. modded.lsl
Get file # 2. Script.lsl
1 // Hazumi Kaze (morphelia.foxclaw):
2 // PIETENPOL AIR CAMPER FLIGHT SCRIPT MK1
3 // Portions of this script are influenced by or based on work from Alex Linden, Cubey Terra, Eoin Widget, Kerian Bunin, Ronald Krugman
4 // Script by Ezekiel Bailly 2005-2008
5 // Copyleft!
6
7
8 // *AC control flags that we set later
9 integer gAngularControls = 0;
10
11
12 // *AC we keep track of angular history for more responsive turns
13 integer gOldAngularLevel = 0;
14
15
16
17 // Landing Gear Weight on Wheels-Collision Integer
18 integer onground = FALSE;
19
20
21 // THROTTLE (SPEED) Sensitive Declarations
22 integer turnrate = 1;
23 integer pitchrate =1;
24
25
26
27 // Thrust variables:
28 // thrust = fwd * thrust_multiplier
29 // Edit the maxThrottle and thrustMultiplier to determine max speed.
30 integer fwd; // this changes when pilot uses throttle controls
31 integer maxThrottle = 5; // Number of "clicks" in throttle control. Arbitrary, really.
32 integer thrustMultiplier = 7; // Amount thrust increases per click.
33
34 // Lift and speed
35 float cruiseSpeed = 19.0; // speed at which plane achieves full lift
36 float lift;
37 float liftMax = 1.5; //Maximum allowable lift
38 float speed;
39 float vertat;
40
41 float timerFreq = 0.5;
42
43 integer fwdLast;
44 integer sit;
45
46
47
48
49 integer acon = FALSE;
50 //integer lightson = FALSE;
51
52
53 integer flight;
54
55 // Control Surface Motion Declarations
56 string last_aileron_direction;
57 string cur_aileron_direction;
58
59 string last_elevator_direction;
60 string cur_elevator_direction;
61
62 string last_rudder_direction;
63 string cur_rudder_direction;
64
65
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
76 // CAMERA_FOCUS,
77 CAMERA_FOCUS_LAG, 0.05,
78 CAMERA_FOCUS_LOCKED, FALSE,
79 CAMERA_FOCUS_THRESHOLD, 0.0,
80
82 CAMERA_POSITION_LAG, 0.3,
83 CAMERA_POSITION_LOCKED, FALSE,
84 CAMERA_POSITION_THRESHOLD, 0.0,
85
86 CAMERA_FOCUS_OFFSET,<0,0,1>//<0,0,1>
87 ];
88 integer camon = FALSE;
89
90
91
92
93 default
94 {
95
96
97
98
100 {
101
102 llListen(0,"",llGetOwner(),"");
103
104 llSetCameraEyeOffset(<-14, 0, 0.5>); // Position of camera, relative to parent.
105 llSetCameraAtOffset(<0, 0, 1.9>); // Point to look at, relative to parent.
106
107
108 llSetSitText("AirCamper"); // Text that appears in pie menu when you sit
109
110 llCollisionSound("", 0.0); // Remove the annoying thump sound from collisions
111
112 //SET VEHICLE PARAMETERS -- See www.secondlife.com/badgeo for an explanation
114
115 // uniform angular friction
117
118 // linear motor
121 llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 2 );
123
124 // agular motor
127 llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 2);
128
129 // hover
134
135 // no linear deflection
138
139 // no angular deflection
142
143 // no vertical attractor
144 //llSetVehicleFloatParam active moved to motors/turning below
145
147
149
150 /// banking
151
152
154 //.4
156 //.95
158 //.1
159
160
164
165
166
167
168 // default rotation of local frame
170
171 // remove these flags
179
180
181
183
184
185 // set these flags
187
188 }
189
190 on_rez(integer num)
191 {
192
193 llOwnerSay("Welcome to the Pietenpol Air Camper, type 'help' for the manual.");
194 llOwnerSay("These controls can be typed in chat:");
195 llOwnerSay("Start the motor: 'contact' , 'cutoff' ");
196 llOwnerSay("Seatposition: 'seatup' 'seatdown' (You will need to Re-sit) ");
197
198 llOwnerSay("If you end up sitting on the cockpit side, stand up and ");
199 llOwnerSay("use 'seatup' or 'seatdown' to reset the seat position. ");
200
201
202
203
205
206
207
208 }
209
210 // DETECT AV SITTING/UNSITTING AND TAKE CONTROLS
211 changed(integer change)
212 {
213 if(change & CHANGED_LINK)
214 {
215 key agent = llAvatarOnSitTarget();
216
217
218
219
220
221
222
223
224
225 // Pilot gets off vehicle
226 if((agent == NULL_KEY) && (sit))
227 {
229 llSetTimerEvent(0.0);
230 llMessageLinked(LINK_SET, 0, "unseated", "");
233
235 sit = FALSE;
236 llSetStatus(STATUS_PHANTOM, TRUE);
237 llSleep(4.0);
238 llSetStatus(STATUS_PHANTOM, FALSE);
239 }
240
241
242
243
244
245
246
247
248
249
250 // Pilot sits on vehicle
251 else if((agent == llGetOwner()) && (!sit))
252 {
254 llSetTimerEvent(timerFreq);
255 llMessageLinked(LINK_SET, 0, "seated", "");
256 llMessageLinked(LINK_ALL_CHILDREN , 0, "CONTROLS_FLYING", NULL_KEY);
257 sit = TRUE;
259 }
260
261
262
263 }
264 }
265
266
267
268
269
270
271
272
273
274 //CHECK PERMISSIONS AND TAKE CONTROLS
276
277
278
279
280 {
282 {
284 }
285 }
286
287
288
289
290
291
292 // LAND COLLISION FILTER FOR STALL BEHAVIOR
293 collision_start(integer num_detected) {
294 onground = TRUE;
295 }
296
297 collision_end(integer num_detected){
298 onground = FALSE;
299 }
300
301
302 land_collision_start(vector pos) {
303 onground = TRUE;}
304
305
306 land_collision_end(vector pos) {
307 onground = FALSE;}
308
309
310
311 //Aircraft Start Watcher
312 link_message(integer send, integer num, string msg, key id)
313 {
314
315
316
317
318
319
320
321
322 if(( msg == "contact" ) && (acon == FALSE))
323 {
324
325 acon= TRUE;
326 llOwnerSay("Starting Engine");
328
329 }
330 else if(( msg == "cutoff" ) && (acon == TRUE) )
331 {
332
333 acon = FALSE;
334 llOwnerSay("Engine Stop");
336
337 }
338
339
340
341
342
343
344
345
346 }
347
348
349
350
351
352 listen( integer channel, string name, key id, string message )
353 {
354
355
356 //Aircraft Start Watcher
357
358 if(( message == "contact" ) && (acon == FALSE))
359 {
360
361 acon= TRUE;
362 llOwnerSay("Starting Engine");
364 }
365 else if(( message == "cutoff" ) && (acon == TRUE) )
366 {
367
368 acon = FALSE;
369 llOwnerSay("Engine Stop");
371 }
372
373 else if((message=="c") && (camon==FALSE))
374 {
375 llSetCameraParams(drive_cam);
376 camon=TRUE;
377 llOwnerSay("Dynamic Camera on");
378 }
379
380 else if((message=="c") && (camon==TRUE))
381 {
383 camon=FALSE;
384 llOwnerSay("Dynamic Camera off");
385 }
386
387
388
389
390
391
392 }
393
394
395
396 //FLIGHT CONTROLS
397 control(key id, integer level, integer edge)
398 {
399
400
401
402
403
404 // OBC DECLARATIONS
405 integer throttle_up = CONTROL_UP;
406 integer throttle_down = CONTROL_DOWN;
407 // integer yoke_fwd = CONTROL_FWD;
408 // integer yoke_back = CONTROL_BACK;
409
410
411
412
413
414
415
416
417 ////////////// THROTTLE INCREASE ////////////////
418
419
420 if((level & throttle_up) && (acon == TRUE))
421 {
422 if(fwd < maxThrottle)
423 {
424 fwd += 1;
425 }
426
427
428 if(fwd == 0)
429 { llOwnerSay("Idle 20%");
430 llSleep(0.5);
432
433
434 if(fwd == 1)
435 { llOwnerSay("Throttle 40%");
436 llSleep(0.05);
438
439
440 if(fwd == 2)
441 { llOwnerSay("Throttle 60%");
442 llSleep(0.05);
444
445
446 if(fwd == 3)
447 { llOwnerSay("Throttle 80%");
448 llSleep(0.05);
450
451
452 if(fwd == 4)
453 { llOwnerSay("Throttle 100%");
454 llSleep(0.05);
456
457
458
459
460
461
462 }
463
464
465
466
467
468 ////////////// THROTTLE DECREASE ////////////////
469
470
471
472
473 else if((level & throttle_down) && (acon == TRUE))
474 {
475 if(fwd > 0)
476 {
477 fwd -= 1;
478 }
479
480
481
482 if(fwd == 0)
483 { llOwnerSay("Idle 20%");
485
486
487
488 if(fwd == 1)
489 { llOwnerSay("Throttle 40%");
491
492 if(fwd == 2)
493 { llOwnerSay("Throttle 60%");
495
496 if(fwd == 3)
497 { llOwnerSay("Throttle 80%");
499
500
501 }
502
503 if(fwd != fwdLast)
504 {
505 llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <(fwd * thrustMultiplier),0,0>);
506
507 // calculate percent of max throttle and send to child prims as link message
508 float thrustPercent = (((float)fwd/(float)maxThrottle) * 100);
509 llMessageLinked(LINK_SET, (integer)thrustPercent, "throttle", "");
510 // llOwnerSay("Throttle at "+(string)((integer)thrustPercent)+"%");
511
512 fwdLast = fwd;
513 llSleep(0.15); // crappy kludge :P
514 }
515
516
517
518
519
520
521 if(speed >= 1)
522 {
523 turnrate = 1;
524 pitchrate =0;
525 vertat =0.15 ;
526 }
527
528
529 if(speed >= 5)
530 {
531 turnrate = 1;
532 pitchrate =0;
533 vertat =.14 ;
534 }
535
536 if(speed >= 10)
537 { turnrate = 1;
538 pitchrate =1;
539 vertat =.13 ;
540 }
541
542
543 if(speed >= 15)
544 {
545 turnrate = 1;
546 pitchrate =2;
547 vertat =.12 ;
548 }
549
550
551 if(speed >= 20)
552 {
553 turnrate = 2;
554 pitchrate =2;
555 vertat =.11 ;
556 }
557
558 if(speed >= 25)
559 { turnrate = 3;
560 pitchrate =3;
561 vertat =.08 ;}
562
563
564 if(speed >= 35)
565 { turnrate = 3;
566 pitchrate =3;
567 vertat =.07 ;}
568
569
570 if(speed >= 40)
571 {
572 turnrate = 3;
573 pitchrate =4;
574 vertat =.06 ;
575 }
576
577
578 if(speed >= 45)
579 {
580 turnrate = 4;
581 pitchrate =4;
582 vertat =.08 ;}
583
584 vector motor;
585 integer motor_changed = level;
586
587
588
590
591
592 // only change angular motor if the angular levels have changed
593 motor_changed = (edge & gOldAngularLevel) + (level & gAngularControls);
594 if(motor_changed)
595 {
596 motor = <0,0,0>;
597 if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT) && (acon == TRUE))
598 {
599 cur_aileron_direction = "AILERON_RIGHT";
600 cur_rudder_direction = "RUDDER_RIGHT";
601 // add roll component ==> triggers banking behavior
602 if(speed > 18) motor.x +=(turnrate);
603
604 // if(geardown == FALSE) motor.x += 4;
605 //3
606 else if(speed <= 18) motor.z -= 2;
607
608
609 }
610
611
612
613 if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT) && (acon == TRUE))
614 {
615 cur_aileron_direction = "AILERON_LEFT";
616 cur_rudder_direction = "RUDDER_LEFT";
617 if(speed > 18) motor.x -=(turnrate);
618
619 // if(geardown == FALSE) motor.x -= 4;
620
621 //4
622 else if(speed <= 18) motor.z += 2;
623
624
625 }
626 if(level & (CONTROL_BACK) && (acon == TRUE)) // CUBEY
627 {
628 // add pitch component ==> causes vehicle lift nose (in local frame)
629 cur_elevator_direction = "ELEVATOR_UP";
630 motor.y -=(pitchrate);
631 }
632 if(level & (CONTROL_FWD) && (acon == TRUE)) // CUBEY
633 {
634 cur_elevator_direction = "ELEVATOR_DOWN";
635 motor.y +=(pitchrate);
636 }
638
639
640 if((~level & edge) && (acon == TRUE))
641 {
642 cur_aileron_direction = "AILERON_NEUTRAL";
643 cur_elevator_direction = "ELEVATOR_NEUTRAL";
644 cur_rudder_direction = "RUDDER_NEUTRAL";
645 }
646
647
648 }
649 // store the angular level history for the next control callback
650 gOldAngularLevel = level & gAngularControls;
651
652
653
654
655
656
657 }
658
659 timer()
660 {
661
662
663
664 if(cur_aileron_direction != last_aileron_direction)
665 {
666 llMessageLinked(LINK_ALL_CHILDREN , 0, cur_aileron_direction, NULL_KEY);
667 last_aileron_direction = cur_aileron_direction;
668 }
669
670
671 if(cur_elevator_direction != last_elevator_direction)
672 {
673 llMessageLinked(LINK_ALL_CHILDREN , 0, cur_elevator_direction, NULL_KEY);
674 last_elevator_direction = cur_elevator_direction;
675 }
676
677 if(cur_rudder_direction != last_rudder_direction)
678 {
679 llMessageLinked(LINK_ALL_CHILDREN , 0, cur_rudder_direction, NULL_KEY);
680 last_rudder_direction = cur_rudder_direction;
681 }
682
683
684
685 // Calculate speed in knots
686 speed = (integer)(llVecMag(llGetVel()) * 1.94384449 + 0.5);
687
688 // Provide lift proportionally to speed
689 cruiseSpeed = 19.0; // speed at which you achieve full lift
690 lift = (speed/cruiseSpeed); //Lift is varied proportionally to the speed
691
692
693 if(lift > liftMax) lift = liftMax;
694
695
696
697 if((speed <= 8) && (onground == FALSE))
698
699 { lift = -2;
700 // llOwnerSay("STALL");
701 flight = FALSE; }
702
703
704
705 // while(!flight)
706 //{
707 // if(speed >=20)
708 // {
709 // flight = TRUE;
710 // }
711 // else
712 // {
713 //// lift = -3;
714 // }
715 //}
716
717
718
719
720
721
723
724
725 }
726
727 }

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