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
Positioning Car  

Car

Car.lsl

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

the Zip file

Download all files for Car
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Car_1.lsl
1
2 //Basic Motorcycle Script
3 //
4 // by Cory
5 // commented by Ben
6
7 //The new vehicle action allows us to make any physical object in Second Life a vehicle. This script is a good example of a
8 // very basic vehicle that is done very well.
9
10 integer loopsnd = 0;
11
12 default
13 {
14
15 //There are several things that we need to do to define vehicle, and how the user interacts with it. It makes sense to
16 // do this right away, in state_entry.
18 {
19
20 //We can change the text in the pie menu to more accurately reflecet the situation. The default text is "Sit" but in
21 // some instances we want you to know you can drive or ride a vehicle by sitting on it. The llSetSitText function will
22 // do this.
23 llSetSitText("Drive");
24
25 //Since you want this to be ridden, we need to make sure that the avatar "rides" it in a acceptable position
26 // and the camera allows the driver to see what is going on.
27 //
28 //llSitTarget is a new function that lets us define how an avatar will orient itself when sitting.
29 // The vector is the offset that your avatar's center will be from the parent object's center. The
30 // rotation is bassed off the positive x axis of the parent. For this motorcycle, we need you to sit in a way
31 // that looks right with the motorcycle sit animation, so we have your avatar sit slightly offset from the seat.
32 llSitTarget(<0.3, 0.0, 0.55>, ZERO_ROTATION);
33
34 //To set the camera, we need to set where the camera is, and what it is looking at. By default, it will
35 // be looking at your avatar's torso, from a position above and behind. It will also be free to rotate around your
36 // avatar when "turning."
37 //
38 //For the motorcycle, we are going to set the camera to be behind the cycle, looking at a point in front of it.
39 // Due to the orientation of the parent object, this will appear to be looking down on the avatar as they navigate
40 // course.
41 llSetCameraEyeOffset(<-5.0, -0.00, 2.0>);
42 llSetCameraAtOffset(<3.0, 0.0, 2.0>);
43
44 //Ask cory "why?"
46
47 //To make an object a vehicle, we need to define it as a vehicle. This is done by assigning it a vehicle type.
48 // A vehicle type is a predefined set of paramaeters that describe how the physics engine should let your
49 // object move. If the type is set to VEHICLE_TYPE_NONE it will no longer be a vehicle.
50 //
51 //The motorcycle uses the car type on the assumption that this will be the closest to how a motorcycle should work.
52 // Any type could be used, and all the parameters redefined later.
54
55
56 //While the type defines all the parameters, a motorcycle is not a car, so we need to change some parameters
57 // to make it behave correctly.
58
59 //The vehicle flags let us set specific behaviors for a vehicle that would not be covered by the more general
60 // parameters. <more needed>
61 llSetVehicleFlags(VEHICLE_FLAG_NO_FLY_UP | VEHICLE_FLAG_LIMIT_ROLL_ONLY);
62
63 //To redefine parameters, we use the function llSetVehicleHippoParam where Hippo is the variable type of the
64 // parameter (float, vector, or rotation).
65 //
66 //Most parameters come in pairs, and efficiency and a timescale. The efficiency defines <more>, while the timescale
67 // defines the time it takes to achive that effect.
68 //
69 //In a virtual world, a motorcycle is a motorcycle because it looks and moves like a motorcycle. The look is
70 // up to the artist who creates the model. We get to define how it moves. The most basic properties of movement
71 // can be thought of as the angular deflection (points in the way it moves) and the linear deflection (moves in the
72 // way it points). A dart would have a high angular deflection, and a low linear deflection. A motorcycle has
73 // a low linear deflection and a high linear deflection, it goes where the wheels send it. The timescales for these
74 // behaviors are kept pretty short.
79
80 //A bobsled could get by without anything making it go or turn except for a icey hill. A motorcycle, however, has
81 // a motor and can be steered. In LSL, these are linear and angular motors. The linear motor is a push, the angular
82 // motor is a twist. We apply these motors when we use the controls, but there is some set up to do. The motor
83 // timescale controls how long it takes to get the full effect of the motor, basically acceleration. The motor decay
84 // timescale defines how long the motor stays at that strength - how slowly you let off the gas pedal.
85 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.3);
88 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.1);
89
90 //<wait for andrew's changes>
93
94 //We are using a couple of tricks to make the motorcycle look like a real motorcycle. We use an animated texture to
95 // spin the wheels. The actual object can not rely on the real world physics that lets a motorcycle stay upright.
96 // We use the vertical attractor parameter to make the object try to stay upright. The vertical attractor also allows
97 // us to make the vehicle bank, or lean into turns.
98 //
99 //<NOT SURE IF FOLLOWING IS RIGHT>
100 //The vertical attaction efficiency is slightly missnamed, as it should be "coefficient." Basically, it controls
101 // if we critically damp to vertical, or "wobble" more. The timescale will control how fast we go back to vertical, and
102 // thus how strong the vertical attractor is.
103 //
104 //We want people to be able to lean into turns,<ugh>
107
108 //Banking means that if we rotate on the roll axis, we will also rotate on the yaw axis, meaning that our motorcycle will lean to the
109 // side as we turn. Not only is this one of the things that make it look like a real motorcycle, it makes it look really cool too. The
110 // higher the banking efficiency, the more "turn" for your "lean". This motorcycle is made to be pretty responsive, so we have a high
111 // efficiency and a very low timescale.
114
115 llCollisionSound("", 0.0);
116 }
117
118
119 //A sitting avatar is treated like a extra linked primitive, which means that we can capture when someone sits on the
120 // vehicle by looking for the changed event, specifically, a link change.
121 changed(integer change)
122 {
123 //Make sure that the change is a link, so most likely to be a sitting avatar.
124 if(change & CHANGED_LINK)
125 {
126 //The llAvatarSitOnTarget function will let us find the key of an avatar that sits on an object using llSitTarget
127 // which we defined in the state_entry event. We can use this to make sure that only the owner can drive our vehicle.
128 // We can also use this to find if the avatar is sitting, or is getting up, because both will be a link change.
129 // If the avatar is sitting down, it will return its key, otherwise it will return a null key when it stands up.
130 key agent = llAvatarOnSitTarget();
131
132 //If sitting down.
133 if(agent)
134 {
135 //We don't want random punks to come stealing our motorcycle! The simple solution is to unsit them,
136 // and for kicks, send um flying.
137 if(agent != llGetOwner())
138 {
139 llSay(0, "You aren't the owner");
140 llUnSit(agent);
141 llPushObject(agent, <0,0,100>, ZERO_VECTOR, FALSE);
142 }
143 // If you are the owner, lets ride!
144 else
145 {
146 //The vehicle works with the physics engine, so in order for a object to act like a vehicle, it must first be
147 // set physical.
149 //There is an assumption that if you are going to choose to sit on a vehicle, you are implicitly giving
150 // permission to let that vehicle act on your controls, and to set your permissions, so the end user
151 // is no longer asked for permission. However, you still need to request these permissions, so all the
152 // paperwork is filed.
154 }
155 }
156 //The null key has been returned, so no one is driving anymore.
157 else
158 {
159 //Clean up everything. Set things nonphysical so they don't slow down the simulator. Release controls so the
160 // avatar move, and stop forcing the animations.
163 llStopAnimation("sit");
164 }
165 }
166
167 }
168
169 //Because we still need to request permissions, the run_time_permissions event still occurs, and is the perfect place to start
170 // the sitting animation and take controls.
172 {
173 if(perm)
174 {
175 llStartAnimation("sit");
177 }
178 }
179
180 //If we want to drive this motorcycle, we need to use the controls.
181 control(key id, integer level, integer edge)
182 {
183 //We will apply motors according to what control is used. For forward and back, a linear motor is applied with a vector
184 // parameter.
185 vector angular_motor;
186
187 if(level & edge & CONTROL_FWD)
188 {
189 // Forward key was initially pressed
191
192 }
193 else if((edge & CONTROL_FWD) && ((level & CONTROL_FWD) == FALSE))
194 {
195 // Forward key was just released
197
198 loopsnd = 0;
199 }
200 else if(level & CONTROL_FWD)
201 {
202 // Forward key was just released
204
205
206 }
207
208 if(level & CONTROL_BACK)
209 {
211 }
213 {
214 angular_motor.x += 100;
215 angular_motor.z -= 100;
216 }
218 {
219 angular_motor.x -= 100;
220 angular_motor.z += 100;
221 }
222 if(level & (CONTROL_UP))
223 {
224 angular_motor.y -= 50;
225 }
226
228 }
229
230 }
231 // END //

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