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 Flight_Script_EEv2  

Flight_Script_EEv2

Flight Script EEv2.lsl

Category: Vehicles
By : Cubey Terra
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Flight_Script_EEv2
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Flight_Script_EEv2_1.lsl
1
2 // Modified from Cubey Terra DIY Plane 1.0 by Eoin Widget and Kerian Bunin
3 // which was originaly marked as September 10, 2005
4
5 // Distribute freely. Go ahead and modify it for your own uses. Improve it and share it around.
6 // Some portions based on the Linden airplane script originall posted in the forums.
7
8 // ** Last Modified by Eoin Widget on March 26, 2006 **
9 // Start up of the plane is now controled by typing the word "start" and shutting it down is is handled by typing stop
10 //It also taxies around on the ground or even on a elivated prim runway.
11 //It uses collision detection when on a prim runway and aswell as ground detection when on the ground.
12 //It uses a count down value in the timer to smooth out the transition between the two modes so that it doesn't switch back and forth while on the ground ebetween the times it detects a collision. To change to ammount of time for this timer change the value of onGroundStartTime.
13 integer onGroundStartTime = 2; //Timer for switching between ground movement and airmovement originaly set to 2
14 vector pos;
15 vector objectPos;
16 integer onGround = FALSE;
17 integer onGroundNext = 0;
18 integer subGround = 0;
19
20
21 // llSitTarget parameters:
22 vector avPosition = <0.0,0.0,-0.6>;//<0.0,0.0,-0.6>; // position of avatar in plane, relative to parent
23 rotation avRotation = <0,-0.2,0,1>;//<0,-0.2,0,1>; // rotation of avatar, relative to parent
24
25 //distance threashhold above ground when the aircraft we turn like a car or bank like a plane, if below this distance it will turn like a car
26 float groundDistance = 5.0;
27
28 // Thrust variables:
29 // thrust = fwd * thrust_multiplier
30 // Edit the maxThrottle and thrustMultiplier to determine max speed.
31 integer fwd; // this changes when pilot uses throttle controls
32 integer maxThrottle = 10; // Number of "clicks" in throttle control. Arbitrary, really.
33 integer thrustMultiplier = 3; // Amount thrust increases per click.
34
35 // Lift and speed
36 float cruiseSpeed = 25.0; // speed at which plane achieves full lift
37 float lift;
38 float liftMax = 0.977; // Maximum allowable lift
39 float speed;
40
41 float timerFreq = 0.5;
42
43 integer fwdLast;
44 integer sit;
45 key owner;
46
47 integer startUp = FALSE;
48 integer camon = FALSE;
49
50 // Defining the Parameters of the normal driving camera.
51 // This will let us follow behind with a loose camera.
52 list drive_cam =
53 [
54 CAMERA_ACTIVE, TRUE,
57 CAMERA_DISTANCE, 10.0,//3.0,
58 PITCH" title="View Definition" class="tooltip">CAMERA_PITCH, 10.0,
59
60 // CAMERA_FOCUS,
61 CAMERA_FOCUS_LAG, 0.05,
62 CAMERA_FOCUS_LOCKED, FALSE,
63 CAMERA_FOCUS_THRESHOLD, 0.0,
64
66 CAMERA_POSITION_LAG, 0.3,
67 CAMERA_POSITION_LOCKED, FALSE,
68 CAMERA_POSITION_THRESHOLD, 0.0,
69
70 CAMERA_FOCUS_OFFSET,<0,0,1>//<0,0,1>
71
72
73 ];
74
75 float vol = 1.0;
76
77 //key motorstart = "jet-startup";
78 //key sound = "Ambient Jet";
79
80 integer geardown = TRUE;
81
82 default
83 {
84
86 {
87 key owner = llGetOwner();
88 llListen(0,"",owner,""); // Listen to owner
89
90 llSitTarget(avPosition, avRotation); // Position and rotation of pilot's avatar.
91
92 llSetCameraEyeOffset(<-12, 0, 2>);//<-7, 0, 1.5>); // Position of camera, relative to parent.
93 llSetCameraAtOffset(<0, 0, 1.9>); // Point to look at, relative to parent.
94
95
96 llSetSitText("Fly!"); // Text that appears in pie menu when you sit
97
98 llCollisionSound("", 0.0); // Remove the annoying thump sound from collisions
99
100 //SET VEHICLE PARAMETERS -- See www.secondlife.com/badgeo for an explanation
102
103 // uniform angular friction
105
106 // linear motor
109 llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 2 );
111
112 // agular motor
115 llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.4);
116
117 // hover
122
123 // no linear deflection
126
127 // no angular deflection
130
131 // no vertical attractor
134
135 /// banking
139
140
141 // default rotation of local frame
143
144 // remove these flags
152
153 // set these flags
155
156 }
157
158 on_rez(integer num)
159 {
161 }
162
163 // DETECT AV SITTING/UNSITTING AND TAKE CONTROLS
164 changed(integer change)
165 {
166 if(change & CHANGED_LINK)
167 {
168 key agent = llAvatarOnSitTarget();
169
170 // Pilot gets off vehicle
171 if((agent == NULL_KEY) && (sit))
172 {
174 llSetTimerEvent(0.0);
175 llMessageLinked(LINK_SET, 0, "unseated", "");
178 sit = FALSE;
179 startUp = FALSE;
181 }
182
183 // Pilot sits on vehicle
184 else if((agent == llGetOwner()) && (!sit))
185 {
187
188 llSetTimerEvent(timerFreq);
189 llMessageLinked(LINK_SET, 0, "seated", "");
190 sit = TRUE;
192 }
193 }
194 }
195
196 //CHECK PERMISSIONS AND TAKE CONTROLS
198 {
200 {
202 }
203 }
204
205 listen( integer channel, string name, key id, string message )
206 {
207
208 if((message=="c")&&(camon==FALSE)&&(sit==TRUE))
209 {
210 llSetCameraParams(drive_cam);
211 camon=TRUE;
212 llOwnerSay("Dynamic Camera on");
213 }
214
215 else if((message=="c")&&(camon==TRUE)&&(sit==TRUE))
216 {
218 camon=FALSE;
219 llOwnerSay("Dynamic Camera off");
220 }
221 else if(( message == "g" ) && (geardown == FALSE)&&(sit==TRUE))
222 {
223 llMessageLinked(LINK_SET, 0, "gear down", NULL_KEY);
224 geardown = TRUE;
225 }
226 else if(( message == "g" ) && (geardown == TRUE)&&(sit==TRUE))
227 {
228 llMessageLinked(LINK_SET, 0, "gear up", NULL_KEY);
229 geardown = FALSE;
230 }
231 }
232
233 collision_start(integer num_detected) {
234 //pos = llDetectedPos(0);
235 onGround = TRUE;
236 //llOwnerSay((string)pos);
237 }
238 collision(integer num_detected) {
239 //pos = llDetectedPos(0);
240 onGround = TRUE;
241 //llOwnerSay((string)pos);
242 }
243 collision_end(integer num_detected) {
244 //pos = <0,0,0>;
245 onGround = FALSE;
246 //llOwnerSay((string)pos);
247 }
248
249 //FLIGHT CONTROLS
250 control(key id, integer level, integer edge)
251 {
252
253 integer throttle_up = CONTROL_UP;
254 integer throttle_down = CONTROL_DOWN;
255 integer yoke_fwd = CONTROL_FWD;
256 integer yoke_back = CONTROL_BACK;
257
258 vector angular_motor;
259
260 if( ( level & CONTROL_LBUTTON ) && ( edge & CONTROL_LBUTTON ) )
261 {
262 llMessageLinked(LINK_SET, 0, "fire", "");
263 }
264 else if( !( level & CONTROL_LBUTTON ) && ( edge & CONTROL_LBUTTON ) )
265 {
266 llMessageLinked(LINK_SET, 0, "cease fire", "");
267 }
268
269 // THROTTLE CONTROL--------------
270 if(level & throttle_up)
271 {
272 if(fwd < maxThrottle)
273 {
274 fwd += 1;
275 }
276 }
277 else if(level & throttle_down)
278 {
279 if(fwd > 0)
280 {
281 fwd -= 1;
282 }
283 }
284
285 if(fwd != fwdLast)
286 {
287 llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <(fwd * thrustMultiplier),0,0>);
288
289 // calculate percent of max throttle and send to child prims as link message
290 float thrustPercent = (((float)fwd/(float)maxThrottle) * 100);
291 llMessageLinked(LINK_SET, (integer)thrustPercent, "throttle", "");
292 llOwnerSay("Throttle at "+(string)((integer)thrustPercent)+"%");
293
294 fwdLast = fwd;
295 llSleep(0.10); // crappy kludge :P
296 }
297
298
299 // PITCH CONTROL ----------------
300 if(level & yoke_fwd)
301 {
302 angular_motor.y = 3.0;
303 }
304 else if(level & yoke_back)
305 {
306 angular_motor.y = -3.0;
307 }
308 else
309 {
310 angular_motor.y = 0;
311 }
312
313
314 // BANKING CONTROL----------------
315 // Eoin Widget modified this part to switch between turning on the z axis for ground movement and turning on the x axis for flight
316
317 if((level & CONTROL_RIGHT) || (level & CONTROL_ROT_RIGHT))
318 {
319 pos = llGetPos();
320 //if(((objectPos.z - pos.z) < groundDistance) && ((objectPos.z - pos.z) > 0))
321 if((onGround) || (( pos.z - llGround(ZERO_VECTOR) ) < groundDistance))
322 {
323 angular_motor.z = -(PI / 4);
324 onGroundNext = onGroundStartTime; //currently set to 2
325 subGround = 0;
326 }
327 else
328 {
329 if(onGroundNext == 0)
330 {
331 subGround = 0;
332 angular_motor.x = TWO_PI;
333 }
334 else if(onGroundNext > 0)
335 {
336 angular_motor.z = -(PI / 4);
337 subGround = 1;
338 }
339 }
340 }
341 else if((level & CONTROL_LEFT) || (level & CONTROL_ROT_LEFT))
342 {
343 pos = llGetPos();
344 //if(((objectPos.z - pos.z) < groundDistance) && ((objectPos.z - pos.z) > 0))
345 if((onGround) || (( pos.z - llGround(ZERO_VECTOR) ) < groundDistance))
346 {
347 angular_motor.z = (PI / 4);
348 onGroundNext = onGroundStartTime; //currently set to 2
349 subGround = 0;
350 }
351 else
352 {
353 if(onGroundNext == 0)
354 {
355 subGround = 0;
356 angular_motor.x = -TWO_PI;
357 }
358 else if(onGroundNext > 0)
359 {
360 angular_motor.z = (PI / 4);
361 subGround = 1;
362 }
363 }
364 }
365
367 }
368
369 timer()
370 {
371 if(startUp) llSetCameraParams(drive_cam);
372 // Calculate speed in knots
373 speed = (integer)(llVecMag(llGetVel()) * 1.94384449 + 0.5);
374
375 // Provide lift proportionally to speed
376 cruiseSpeed = 25.0; // speed at which you achieve full lift
377 lift = (speed/cruiseSpeed); //Lift is varied proportionally to the speed
378 if(lift > liftMax) lift = liftMax;
380
381 if((onGroundNext > 0) && (subGround == 1)) onGroundNext -= subGround; //Eoin Widget - part of ground movement calculations, a timer to make ground movements smoother, won't switch over flight rotation untill onGroundNext is 0
382 }
383
384 }// END //

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