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
Flight Assist Andrew_Lindens_flight_script  

Andrew_Lindens_flight_script

Andrew Linden's flight script.lsl

Category: Flight Assist
By : Andrew Linden
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Andrew_Lindens_flight_script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Andrew_Lindens_flight_script_1.lsl
1
2 // Simple airplane script example
3
4 // THIS SCRIPT IS PUBLIC DOMAIN! Do not delete the credits at the top of this script!
5
6 // Nov 25, 2003 - created by Andrew Linden and posted in the Second Life scripting forum
7 // Jan 05, 2004 - Cubey Terra - minor changes: customized controls, added enable/disable physics events
8 // Feel free to copy, modify, and use this script.
9
10 // Always give credit to Andrew Linden and all people who modify it in a readme or in the object description.
11
12
13
14 // assumes that the root primitive is oriented such that its
15 // local x-axis points toward the nose of the plane, and its
16 // local z-axis points toward the top
17
18 // control flags that we set later
19 integer gAngularControls = 0;
20 integer gLinearControls = 0;
21
22 // we keep track of angular history for more responsive turns
23 integer gOldAngularLevel = 0;
24
25 // the linear motor uses an accumulator model rather than keeping track
26 // of the linear control level history
27 vector gLinearMotor = <0, 0, 0>;
28
29 default
30 {
32 {
33 llSetSitText("Fly");
34 llCollisionSound("", 0.0);
35
36 // the sit and camera placement is very shape dependent
37 // so modify these to suit your vehicle
38 llSitTarget(<0.6, 0.0, 0.20>, ZERO_ROTATION);
39 llSetCameraEyeOffset(<-10.0, 0.0, 2.0> );
40 llSetCameraAtOffset(<3.0, 0.0, 1.0> );
41
43
44 // weak angular deflection
47
48 // strong linear deflection
51
52 // somewhat responsive linear motor
53 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.5);
55
56 // somewhat responsive angular motor, but with 3 second decay timescale
58 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 3);
59
60 // very weak friction
61 //llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1000.0, 1000.0, 1000.0> ); // CUBEY - original line
62 llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <200, 20, 20> ); // CUBEY - increased friction
64
65 llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.65); // almost wobbly - CUBEY - increased from .25 to improve stability
67
70 llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 0.95); // more banking when moving
71
72 // hover can be better than sliding along the ground during takeoff and landing
73 // but it only works over the terrain (not objects)
78
79 // non-zero buoyancy helps the airplane stay up
80 // set to zero if you don't want this crutch
82
83 // define these here for convenience later
84 // CUBEY - modified these as per Shadow's prefs
86 gLinearControls = CONTROL_UP | CONTROL_DOWN;
87
88 llSetStatus(STATUS_PHYSICS, FALSE); //CUBEY - ensure that physics are disabled when plane is rezzed so it doesn't fly off
89 }
90
91 changed(integer change)
92 {
93 if(change & CHANGED_LINK)
94 {
95 key agent = llAvatarOnSitTarget();
96 if(agent)
97 {
98 if(agent != llGetOwner())
99 {
100 // only the owner can use this vehicle
101 llSay(0, "You aren't the owner -- only the owner can fly this plane.");
102 llUnSit(agent);
103 llPushObject(agent, <0,0,10>, ZERO_VECTOR, FALSE);
104 }
105 else
106 {
107 // clear linear motor on successful sit
108 gLinearMotor = <0, 0, 0>;
110
115 }
116 }
117 else
118 {
119 // stop the motors
120 gLinearMotor = <0, 0, 0>;
123
124 // use friction to stop the vehicle rather than pinning it in place
128
129 // driver is getting up
131 llStopAnimation("sit");
132 llSetStatus(STATUS_PHYSICS, FALSE); //CUBEY - turn off physics to make sure the parked plane can't be moved
133 }
134 }
135
136 }
137
139 {
140 if(perm)
141 {
142 llStartAnimation("sit");
143 llTakeControls(gAngularControls | gLinearControls, TRUE, FALSE);
144 llSetStatus(STATUS_PHYSICS, TRUE); //CUBEY - enable physics when avatar sits
145 }
146 }
147
148 control(key id, integer level, integer edge)
149 {
150 // only change linear motor if one of the linear controls are pressed
151 vector motor;
152 integer motor_changed = level & gLinearControls;
153 if(motor_changed)
154 {
155 if(level & CONTROL_UP) //CUBEY
156 {
157 if(gLinearMotor.x < 0)
158 {
159 gLinearMotor.x = 0;
160 }
161 else if(gLinearMotor.x < 30)
162 {
163 gLinearMotor.x += 5;
164 }
165 motor_changed = TRUE;
166 }
167 if(level & CONTROL_DOWN) //CUBEY
168 {
169 if(gLinearMotor.x > 0)
170 {
171 gLinearMotor.x = 0;
172 }
173 else if(gLinearMotor.x > -30)
174 {
175 gLinearMotor.x -= 5;
176 };
177 motor_changed = TRUE;
178 }
180 }
181
182 // only change angular motor if the angular levels have changed
183 motor_changed = (edge & gOldAngularLevel) + (level & gAngularControls);
184 if(motor_changed)
185 {
186 motor = <0,0,0>;
188 {
189 // add roll component ==> triggers banking behavior
190 motor.x += 10;
191 }
193 {
194 motor.x -= 10;
195 }
196 if(level & (CONTROL_BACK)) // CUBEY
197 {
198 // add pitch component ==> causes vehicle lift nose (in local frame)
199 motor.y -= 8;
200 }
201 if(level & (CONTROL_FWD)) // CUBEY
202 {
203 motor.y += 8;
204 }
206 }
207 // store the angular level history for the next control callback
208 gOldAngularLevel = level & gAngularControls;
209 }
210 }
211 // END //

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