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 Simple_Airplane_1  

Simple_Airplane_1

Simple Airplane 1.0.lsl

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

the Zip file

Download all files for Simple_Airplane_1
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Simple_Airplane_1_1.lsl
1
2 // simple airplane script example
3 //Last edited by Andrew Linden on 12-08-2003 at 02:31 PM
4
5 // assumes that the root primitive is oriented such that its
6 // local x-axis points toward the nose of the plane, and its
7 // local z-axis points toward the top
8
9 //if the root primitive of your airplane does not have the same orientation as the whole airplane
10 //(i.e. local x-axis = forward, local y-axis = left, local z-axis = up) then the script will not push
11 //your airplane in the "correct" direction.
12 //
13 //You need to either:
14 //
15 //1. orient your root primitive to agree with the airplane's axes of motion
16 //2. pick a different primitive to be the root (one whose local axes agree with those of the airplane's motion)
17 //3. use the VEHICLE_REFERENCE_FRAME parameter (this is an advanced topic and is outside the scope of a _simple_ airplane script)
18
19 // control flags that we set later
20 integer gAngularControls = 0;
21 integer gLinearControls = 0;
22
23 // we keep track of angular history for more responsive turns
24 integer gOldAngularLevel = 0;
25
26 // the linear motor uses an accumulator model rather than keeping track
27 // of the linear control level history
28 vector gLinearMotor = <0, 0, 0>;
29
30 default
31 {
33 {
34 llSetSitText("Fly");
35 llCollisionSound("", 0.0);
36
37 // the sit and camera placement is very shape dependent
38 // so modify these to suit your vehicle
39 llSitTarget(<0.6, 0.05, 0.20>, ZERO_ROTATION);
40 llSetCameraEyeOffset(<-10.0, 0.0, 2.0> );
41 llSetCameraAtOffset(<3.0, 0.0, 1.0> );
42
44
45 // weak angular deflection
48
49 // strong linear deflection
52
53 // somewhat responsive linear motor
54 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.5);
56
57 // somewhat responsive angular motor, but with 3 second decay timescale
59 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 3);
60
61 // very weak friction
64
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 gAngularControls = CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT
86 gLinearControls = CONTROL_FWD | CONTROL_BACK;
87
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");
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("motorcycle_sit");
132 }
133 }
134
135 }
136
138 {
139 if(perm)
140 {
141 llStartAnimation("motorcycle_sit");
142 llTakeControls(gAngularControls | gLinearControls, TRUE, FALSE);
143 }
144 }
145
146 control(key id, integer level, integer edge)
147 {
148 // only change linear motor if one of the linear controls are pressed
149 vector motor;
150 integer motor_changed = level & gLinearControls;
151 if(motor_changed)
152 {
153 if(level & CONTROL_FWD)
154 {
155 if(gLinearMotor.x < 0)
156 {
157 gLinearMotor.x = 0;
158 }
159 else if(gLinearMotor.x < 30)
160 {
161 gLinearMotor.x += 5;
162 }
163 motor_changed = TRUE;
164 }
165 if(level & CONTROL_BACK)
166 {
167 if(gLinearMotor.x > 0)
168 {
169 gLinearMotor.x = 0;
170 }
171 else if(gLinearMotor.x > -30)
172 {
173 gLinearMotor.x -= 5;
174 };
175 motor_changed = TRUE;
176 }
178 }
179
180 // only change angular motor if the angular levels have changed
181 motor_changed = (edge & gOldAngularLevel) + (level & gAngularControls);
182 if(motor_changed)
183 {
184 motor = <0,0,0>;
186 {
187 // add roll component ==> triggers banking behavior
188 motor.x += 10;
189 }
191 {
192 motor.x -= 10;
193 }
194 if(level & (CONTROL_UP))
195 {
196 // add pitch component ==> causes vehicle lift nose (in local frame)
197 motor.y -= 8;
198 }
199 if(level & (CONTROL_DOWN))
200 {
201 motor.y += 8;
202 }
204 }
205 // store the angular level history for the next control callback
206 gOldAngularLevel = level & gAngularControls;
207 }
208 }
209 // END //

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