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
Underwater Motorcycle  

Motorcycle

Motorcycle.lsl

Category: Underwater
By : Cory Linden
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Motorcycle
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Motorcycle_1.lsl
1
2 1 // Remove That 1 to make the Script Running
3 // example motorcycle script
4 //
5 // Originally written by Cory Linden.
6 // Then modified and tweaked by Andrew Linden for the forum script library.
7 //
8 // Root prim should be oriented such that its local X-, Y- and Z-axes are
9 // parallel to forward, left, and up respectively.
10 //
11 // Sound triggers are commented out but not removed, so if you
12 // want sounds, just add the sounds to the cycle's contents and uncomment
13 // the triggers.
14 //
15 // Be careful when changing parameters. Some of them can be very
16 // sensitive to change, such that a change of less than 5% can have a
17 // noticable effect. You can tell some (but not necessarily all) of the
18 // more sensitive settings in this example by looking for the ones that
19 // have been set to double precission. Changing only one at a time is a
20 // good idea.
21 //
22 // The geometry of the motorcycle itself can have significant impact on
23 // whether it in a straight line when not trying to turn. For best results
24 // use asymmetric design with as wide of a base as you can tolerate.
25
26 // These are globals only for convenience (so when you need to modify
27 // them you need only make a single change). There are other magic numbers
28 // below that have not yet been pulled into globals.
29 float gMaxTurnSpeed = 12;
30 float gMaxWheelieSpeed = 5;
31 float gMaxFwdSpeed = 30;
32 float gMaxBackSpeed = -10;
33 float gAngularRamp = 0.17;
34 float gLinearRamp = 0.2;
35
36 // These are true globals whose values are "accumulated" over
37 // multiple control() callbacks.
38 float gBank = 0.0;
39 vector gLinearMotor = <0, 0, 0>;
40 vector gAngularMotor = <0, 0, 0>;
41
42 default
43 {
45 {
46 // init stuff that never changes
47 llSetSitText("Ride");
48 llCollisionSound("", 0.0);
49 llSitTarget(<0.6, 0.05, 0.20>, ZERO_ROTATION);
50 llSetCameraEyeOffset(<-6.0, 0.0, 1.0> );
51 llSetCameraAtOffset(<3.0, 0.0, 1.0> );
52
53 // create the vehicle
62
63 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.8);
66 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.35);
67
70
73
77
81 }
82
83 changed(integer change)
84 {
85 if(change & CHANGED_LINK)
86 {
87 key agent = llAvatarOnSitTarget();
88 if(agent)
89 {
90 if(agent != llGetOwner())
91 {
92 // owner has mounted
93 llSay(0, "You aren't the owner");
94 llUnSit(agent);
95 llPushObject(agent, <0,0,100>, ZERO_VECTOR, FALSE);
96 }
97 else
98 {
99 // not the owner ==> boot off
102 //llSound("start", 0.40, FALSE, FALSE);
103
104 // reset the global accumulators
105 gAngularMotor = <0, 0, 0>;
106 gLinearMotor = <0, 0, 0>;
107 gBank = 0.0;
108 }
109 }
110 else
111 {
112 // dismount
115 llStopAnimation("motorcycle_sit");
116 //llSound("off", 0.4, FALSE, TRUE);
117 }
118 }
119
120 }
121
123 {
124 if(perm)
125 {
126 llStartAnimation("motorcycle_sit");
129 //llSound("on", 1.0, TRUE, TRUE);
130 }
131 }
132
133 control(key id, integer level, integer edge)
134 {
135 // The idea here is to ramp up the motors when the keys are held down for a long
136 // time and to let the motors decay after they are let go. This allows fine-
137 // tuning of the motion of the vehicle by throttling the key controls.
138 //
139 // Note that this probably doesn't work well when the client FPS and/or the server
140 // FPS is lagging. So for best results you'll want to turn off as much visual
141 // effects as you can tolerate, and drive in the more empty areas.
142
143 // linear
144 integer key_control = FALSE;
145 if(level & CONTROL_FWD)
146 {
147 gLinearMotor.x = gLinearMotor.x + gLinearRamp * (gMaxFwdSpeed - gLinearMotor.x);
148 key_control = TRUE;
149 }
150 if(level & CONTROL_BACK)
151 {
152 gLinearMotor.x = gLinearMotor.x + gLinearRamp * (gMaxBackSpeed - gLinearMotor.x);
153 key_control = TRUE;
154 }
155 if(key_control)
156 {
158 key_control = FALSE;
159 }
160 else
161 {
162 if(gLinearMotor.x > 15 || gLinearMotor.x < -5)
163 {
164 // Automatically reduce the motor if keys are let up when moving fast.
165 gLinearMotor.x *= 0.8;
167 }
168 else
169 {
170 // reduce the linear motor accumulator for the next control() event
171 gLinearMotor.x *= 0.8;
172 }
173 }
174
175 // angular
177 {
178 gAngularMotor.x = gAngularMotor.x + gAngularRamp * (gMaxTurnSpeed - gAngularMotor.x);
179 key_control = TRUE;
180 }
182 {
183 gAngularMotor.x = gAngularMotor.x - gAngularRamp * (gMaxTurnSpeed + gAngularMotor.x);
184 key_control = TRUE;
185 }
186 if(level & CONTROL_UP)
187 {
188 gAngularMotor.y = gAngularMotor.y - gAngularRamp * (gMaxWheelieSpeed + gAngularMotor.y);
189 key_control = TRUE;
190 }
191 if(key_control)
192 {
193 // turn on banking and apply angular motor
194 gBank = 3.0;
197 gAngularMotor *= 0.95; // light attenuation
198 }
199 else
200 {
201 if(gAngularMotor.x > 4
202 || gAngularMotor.x < -4)
203 {
204 // We were turning hard, but no longer ==> reduce banking to help
205 // the motorcycle travel straight when bouncing on rough terrain.
206 // Also, turn off the angular motor ==> faster upright recovery.
207 gAngularMotor *= 0.4;
208 gBank *= 0.5;
211 }
212 else
213 {
214 // reduce banking for straigher travel when not actively turning
215 gAngularMotor *= 0.5;
216 gBank *= 0.8;
218 }
219 }
220 }
221 }
222 // END //

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