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 Hoverboard  

Hoverboard

Hoverboard.lsl

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

the Zip file

Download all files for Hoverboard
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Hoverboard_1.lsl
1
2 integer sit = FALSE;
3 integer sitterlinknum = 9;
4
5 key avatar;
6
7 float mass;
8
9 float SIT_DROP = 0.15; // Looks cool when you jump on
10 float ROTATION_RATE = 5.0; // Rate of turning
11 float TIMER_DELAY = 0.1;
12 float JUMP_FORCE = 75.0;
13 float JUMP_ROTATE = 50.0; // Force to rotate on jump
14 float JUMP_PITCH = 7.0; // Force to pitch nose upward during a jump
15 float THRUST_PITCH = 3.0; // Force to pitch nose upward on thrusting fwd/back
16 float LAND_ROTATE = 15.0; // Nose tips on landing
17 float HOVER_HEIGHT = 2.0; // How high to hover while flying
18 float PRE_JUMP = 0.5; // How far to come down when readying for jump
19 float MAX_JUMP_TIME = 2.0; // Max secs to accumulate energy for jump
20 float FWD_THRUST = 60.0; // Forward thrust motor force
21 float BACK_THRUST = 10.0; // Backup thrust
22 float FOLLOW_SCALE = 10.0; // Extra boost to push upward for upcoming hills
23 float FOLLOW_THRESHOLD = 0.35; // Threshold for when to apply extra force
24 float AUTO_JUMP_THRESHOLD = 5.0;
25 float STUMBLE = -1.0; // Z-vel on landing that triggers stumble
26
27 float TRICK_RATE = 15.0;
28
29 vector PUSH_OFF = <0, 25, 75>;
30 float MAX_JUMP_DURATION = 15.0; // Jumps longer than this will be ended (like if you land on a house!)
31
32 vector LINEAR_FRICTION_RIDE = <10.0, 5.0, 1000.0>; // Friction while riding
33 vector LINEAR_FRICTION_BRAKE = <0.5, 0.5, 1000.0>; // Friction while braking
34
35 float jump_timer = 0.0;
36 float height_agl = 0.0;
37 float ground_height = 0.0;
38 float water_height = 0.0;
39 integer timer_count = 0;
40 vector pos;
41 vector vel;
42 rotation rot;
43 float vel_mag;
44 float follow_diff;
45 float cur_time;
46
47 integer is_jumping = FALSE;
48 integer left_toggle = FALSE;
49 integer right_toggle = FALSE;
50 integer up_toggle = FALSE;
51 integer fwd_toggle = FALSE;
52 integer back_toggle = FALSE;
53 integer down_toggle = FALSE;
54
55 integer over_water = FALSE;
56
57 reset_keys()
58 {
59 up_toggle = FALSE;
60 fwd_toggle = FALSE;
61 back_toggle = FALSE;
62 left_toggle = FALSE;
63 right_toggle = FALSE;
64 down_toggle = FALSE;
65 }
66
67 start_jump(float mag)
68 {
69 //
70 // This function is called to start a jump
71 //
72 vector imp = <0, 0, JUMP_FORCE> * mass * mag;
74 jump_timer = llGetTime();
75 //llApplyRotationalImpulse(<0,-JUMP_ROTATE*mag,0>, TRUE);
76 llMessageLinked(LINK_SET, 0, "jump", "");
77 //llTriggerSound("jump", 0.25 + mag);
78 //llLoopSound("jumping", 0.3);
82 is_jumping = TRUE;
83 }
84 stop_jump()
85 {
86 is_jumping = FALSE;
88 llApplyRotationalImpulse(<0,-LAND_ROTATE*mass,0>, TRUE);
89 llMessageLinked(LINK_SET, 0, "landing", "");
90 vel = llGetVel();
91 llTriggerSound("land", 0.5);
93 if(vel.z < STUMBLE)
94 {
95 //llStartAnimation("hello");
96 }
97 }
98 trick()
99 {
100 llStartAnimation("backflip");
101 llTriggerSound("trick", 0.5);
103 llSleep(1.0);
105 }
106
107 default
108 {
110 {
111
112 mass = llGetMass();
113
114 llSitTarget(<-0.5, 0.0, 1.0>, <0,0,0,1>); // Set seating location. Change for different height AVs
116
119 llSetVehicleFlags(VEHICLE_FLAG_NO_FLY_UP);
120
125
126 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.5);
129 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 50.0);
130
132
134
138
140
143
147
148
149 llSetCameraEyeOffset(<-10.0, 1.0, 3.0>);
150 llSetSitText("Ride");
151 llSetCameraAtOffset(<0, 1.0, 0>);
152
153 llSetTimerEvent(TIMER_DELAY);
154
155 }
157 {
159 {
160 llWhisper(0, "Buy me! Right click and choose 'Buy' then take me out of your inventory to ride!");
161
162 }
163 else
164 {
165 llTriggerSound("takeout", 0.5);
166 llWhisper(0, "Are you are avatar enough to ride me? Right Click, and choose 'Ride' from the pie menu.");
167 rot = llGetRot();
168 rot = llEuler2Rot(<0,0,PI/4.0>) * rot;
169 llSetRot(rot);
170 }
171 }
172 on_rez(integer param)
173 {
174 // Preload sounds so they are ready for use
175 llTriggerSound("takeout", 1.0);
176 llPreloadSound("start_up2.wav");
177 llPreloadSound("shut_down2.wav");
178 llPreloadSound("jump");
179 llPreloadSound("pre_jump");
180 llPreloadSound("brake");
181 llPreloadSound("land");
182 }
183
184 changed(integer change)
185 {
186 avatar = llAvatarOnSitTarget();
187 if(change & CHANGED_LINK)
188 {
189 if(avatar == NULL_KEY)
190 {
191 //
192 // You have gotten off your bike
193 //
194 llMessageLinked(LINK_SET, 0, "idle", "");
195 llPlaySound("shut_down2.wav",0.7);
198 llStopAnimation("surf");
199 sit = FALSE;
200 llSetTimerEvent(0.0);
201 llPushObject(llGetOwner(), PUSH_OFF, <0,0,0>, TRUE); // Help you off the bike
202 }
203 else if(avatar == llGetOwner())
204 {
205 //
206 // You have gotten on your bike
207 //
208 llMessageLinked(LINK_SET, 0, "get_on", "");
209 llPlaySound("start_up2.wav", 0.7);
211 sit = TRUE;
213 reset_keys();
214 llSetTimerEvent(TIMER_DELAY);
215 }
216 else
217 {
218 llSay(0, "Please step away from the hoverboard.");
219 llUnSit(avatar);
220 }
221 }
222 }
223
225 {
227 {
228 llStopAnimation("sit");
229 llStartAnimation("surf");
231 llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, HOVER_HEIGHT - SIT_DROP);
232 llSleep(0.5);
234 }
235 else
236 {
237 llUnSit(avatar);
238 }
239 }
240
241 control(key id, integer level, integer edge)
242 {
243 if(((edge) & CONTROL_LEFT) | ((edge) & CONTROL_ROT_LEFT))
244 {
245 left_toggle = !left_toggle;
246 if(left_toggle)
247 {
248 llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <-ROTATION_RATE,0,ROTATION_RATE/2.0>);
249 }
250 else
251 {
253 }
254 }
255 if((level & CONTROL_LEFT) | (level & CONTROL_ROT_LEFT)) left_toggle = TRUE;
256
257 if(((edge) & CONTROL_RIGHT) | ((edge) & CONTROL_ROT_RIGHT))
258 {
259 right_toggle = !right_toggle;
260 if(right_toggle)
261 {
262 llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <ROTATION_RATE,0,-ROTATION_RATE/2.0>);
263 }
264 else
265 {
267 }
268 }
269 if((level & CONTROL_RIGHT) | (level & CONTROL_ROT_RIGHT)) right_toggle = TRUE;
270
271 if(edge & CONTROL_FWD)
272 {
273 fwd_toggle = !fwd_toggle;
274 if(fwd_toggle && !is_jumping)
275 {
277 llApplyRotationalImpulse(<0,-THRUST_PITCH*mass,0>, TRUE);
278 llMessageLinked(LINK_SET, 0, "burst", "");
279 }
280 else
281 {
283 }
284 }
285
286 if(edge & CONTROL_BACK)
287 {
288 back_toggle = !back_toggle;
289 if(back_toggle)
290 {
291 if(!is_jumping)
292 {
293 llTriggerSound("brake", 1.0);
295 llApplyRotationalImpulse(<0,THRUST_PITCH*mass,0>, TRUE);
296 }
297 else
298 {
299 trick();
300 }
301 }
302 else
303 {
306 }
307 }
308
309 if(level & CONTROL_FWD)
310 {
312 llMessageLinked(LINK_SET, 0, "drive", "");
313 fwd_toggle = TRUE;
314 }
315 if(level & CONTROL_BACK)
316 {
318 back_toggle = TRUE;
319 }
320
321
322 if(edge & CONTROL_UP)
323 {
324 up_toggle = !up_toggle;
325 //
326 if(!up_toggle)
327 {
328 // Key released so jump!
329 float mag = (llGetTime() - jump_timer)/MAX_JUMP_TIME;
330 if(mag > 1.0) mag = 1.0;
331 llStartAnimation("surf");
332 start_jump(mag);
333 }
334 else
335 {
336 // Key pressed so get ready
337 jump_timer = llGetTime();
338 llStartAnimation("hello");
339 llApplyRotationalImpulse(<0,-THRUST_PITCH*mass,0>, TRUE);
340 llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, HOVER_HEIGHT - PRE_JUMP);
341 llTriggerSound("pre_jump", 1.0);
342
343 }
344 }
345
346 if(edge & CONTROL_DOWN)
347 {
348 down_toggle = !down_toggle;
349 if(down_toggle)
350 {
351 llTriggerSound("brake", 1.0);
353 }
354 else
355 {
357 }
358 }
359
360 }
361 timer()
362 {
363 // check for ground and do stuff
364 timer_count++;
365 cur_time = llGetTime() - jump_timer;
366 if(is_jumping && (cur_time > 0.5))
367 {
368 pos = llGetPos();
369 water_height = llWater(<0,0,0>);
370 ground_height = llGround(<0,0,0>);
371 if(water_height > ground_height)
372 {
373 height_agl = pos.z - water_height - 0.5;
374 }
375 else
376 {
377 height_agl = pos.z - ground_height - 0.5;
378 }
379 if((height_agl < HOVER_HEIGHT) || (cur_time > MAX_JUMP_DURATION))
380 {
381 stop_jump();
382 }
383 }
384 else
385 {
386 //
387 // On ground, so follow contour
388 //
389 pos = llGetPos();
390 vel = llGetVel();
391 vel_mag = llVecMag(vel);
392 water_height = llWater(llGetVel()*TIMER_DELAY);
393 ground_height = llGround(llGetVel()*TIMER_DELAY);
394 if(water_height > ground_height)
395 {
396 follow_diff = pos.z - water_height - HOVER_HEIGHT + 0.45;
397 if(!over_water)
398 {
399 over_water = TRUE;
400 llMessageLinked(LINK_SET, 0, "over_water", "");
401 }
402 }
403 else
404 {
405 if(over_water)
406 {
407 over_water = FALSE;
408 llMessageLinked(LINK_SET, 0, "over_ground", "");
409 }
410
411 follow_diff = pos.z - ground_height - HOVER_HEIGHT + 0.45;
412 }
413 if((follow_diff < -FOLLOW_THRESHOLD) && (vel_mag > 2.0))
414 {
415 llApplyImpulse(<0,0,-follow_diff*FOLLOW_SCALE>, TRUE);
416 //llSay(0, "push " + (string) follow_diff);
417 }
418 if(!is_jumping && (follow_diff > AUTO_JUMP_THRESHOLD))
419 {
420 //llSay(0,"jump!");
421 start_jump(0.1);
422 }
423
424 }
425
426 }
427 }// END //

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