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 Realistic_Car  

Realistic_Car

Realistic Car.lsl

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

the Zip file

Download all files for Realistic_Car
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Realistic_Car_1.lsl
Get file # 2. Realistic_Car_Front_Wheel_1.lsl
Get file # 3. Realistic_Car_Instructions_1.lsl
Get file # 4. Realistic_Car_Rear_Wheel_1.lsl
Get file # 5. Realistic_Car_Seat_1.lsl
Get file # 6. Realistic_Car_with_remote_mod_1.lsl
1
2 //**********************************************
3 //Title: Car
4 //Author: Aaron Perkins
5 //Date: 3/17/2004
6 //**********************************************
7
8 //Feel free to modify these basic parameters to suit your needs.
9 float forward_power = 30; //Power used to go forward (1 to 30)
10 float reverse_power = -15; //Power ued to go reverse (-1 to -30)
11 float turning_ratio = 4.0; //How sharply the vehicle turns. Less is more sharply. (.1 to 10)
12 string sit_message = "Jump In!"; //Sit message
13 string not_owner_message = "You are not the owner of this vehicle ..."; //Not owner message
14
15 //Anything past this point should only be modfied if you know what you are doing
16 string last_wheel_direction;
17 string cur_wheel_direction;
18
19 default
20 {
22 {
23 llSetSitText(sit_message);
24
25 llSetCameraEyeOffset(<-10.0, 0.0, 2.0> );
26 llSetCameraAtOffset(<10.0, 0.0, 2.0> );
27
28 //car
34 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.0);
37 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.5);
42 }
43
44 changed(integer change)
45 {
46 if(change & CHANGED_LINK)
47 {
48 key agent = llAvatarOnSitTarget();
49 if(agent)
50 {
51 if(agent != llGetOwner())
52 {
53 llSay(0, not_owner_message);
54 llUnSit(agent);
55 llPushObject(agent, <0,0,50>, ZERO_VECTOR, FALSE);
56 }
57 else
58 {
59 llTriggerSound("car_start",1);
60
61 llMessageLinked(LINK_ALL_CHILDREN , 0, "WHEEL_DRIVING", NULL_KEY);
62 llSleep(.4);
64 llSleep(.1);
66
67 llSetTimerEvent(0.1);
68 llLoopSound("car_idle",1);
69 }
70 }
71 else
72 {
75
77 llSleep(.1);
78 llMessageLinked(LINK_ALL_CHILDREN , 0, "WHEEL_DEFAULT", NULL_KEY);
79 llSleep(.4);
81
83 }
84 }
85
86 }
87
89 {
90 if(perm)
91 {
94 }
95 }
96
97 control(key id, integer level, integer edge)
98 {
99 integer reverse=1;
100 vector angular_motor;
101
102 //get current speed
103 vector vel = llGetVel();
104 float speed = llVecMag(vel);
105
106 //car controls
107 if(level & CONTROL_FWD)
108 {
109 cur_wheel_direction = "WHEEL_FORWARD";
111 reverse=1;
112 }
113 if(level & CONTROL_BACK)
114 {
115 cur_wheel_direction = "WHEEL_REVERSE";
117 reverse = -1;
118 }
119
121 {
122 cur_wheel_direction = "WHEEL_RIGHT";
123 angular_motor.z -= speed / turning_ratio * reverse;
124 }
125
127 {
128 cur_wheel_direction = "WHEEL_LEFT";
129 angular_motor.z += speed / turning_ratio * reverse;
130 }
131
133
134 } //end control
135
136 timer()
137 {
138 if(cur_wheel_direction != last_wheel_direction)
139 {
140 llMessageLinked(LINK_ALL_CHILDREN , 0, cur_wheel_direction, NULL_KEY);
141 last_wheel_direction = cur_wheel_direction;
142 }
143 }
144
145 } //end default
146 // END //

Realistic_Car

Realistic Car Front Wheel.lsl

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

1
2 //**********************************************
3 //Title: Car Front Wheel
4 //Author: Aaron Perkins
5 //Date: 2/17/2004
6 //**********************************************
7
8 rotation Inverse(rotation r)
9 {
10 r.x = -r.x;
11 r.y = -r.y;
12 r.z = -r.z;
13 return r;
14 }
15 rotation GetParentRot()
16 {
17 return Inverse(llGetLocalRot())*llGetRot();
18 }
19 SetLocalRot(rotation x)
20 {
21 llSetRot(x*Inverse(GetParentRot()));
22 }
23
24 default
25 {
27 {
28 }
29
30 link_message(integer sender_num, integer num, string str, key id)
31 {
32 if(str == "WHEEL_DRIVING")
33 {
34 state driving;
35 }
36 }
37
38 }
39
40 state driving
41 {
43 {
44 SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO,0,0> ));
45 llSetTimerEvent(0.5);
46 }
47
48 timer()
49 {
50 vector vel = llGetVel();
51 float speed = llVecMag(vel);
53 }
54
55 link_message(integer sender_num, integer num, string str, key id)
56 {
57 if(str == "WHEEL_DEFAULT")
58 {
59 state default;
60 }
61
62 if(str == "WHEEL_FORWARD")
63 {
64 SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO,0,0> ));
65 }
66
67 if(str == "WHEEL_REVERSE")
68 {
69 SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO,0,0> ));
70 }
71
72 if(str == "WHEEL_LEFT")
73 {
74 SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO, -1 * PI_BY_TWO / 2, 0> ));
75 }
76
77 if(str == "WHEEL_RIGHT")
78 {
79 SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO, PI_BY_TWO / 2, 0> ));
80 }
81
82 }
83
85 {
86 SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO,0,0> ));
87 llSetTextureAnim(0,ALL_SIDES,0,0,0,0,0);
88 }
89
90 }
91 // END //

Realistic_Car

Realistic Car Instructions .lsl

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

1
2 Realistic Car Script
3 This a respost from the other forum to mak it easier to find. Also you can get this script along with a sample car for L$1 at my shop. Look for the big glass tower (Rose, 158, 140).
4
5 Here is my submission to the community.
6
7 This a realistic car script. Three main features make it more realistic than your average car script.
8
9 1. You can't turn the car if you are not moving.
10
11 2. The tires rotate when you move and the front wheels turn when you turn.
12
13 3. Reverse steering works the right way.
14
15 There are three parts to this script.
16
17 1. car_main: Goes on the root prim of your vehicle. The "front" of the vehicle will the the postive X axis.
18
19 2. car_seat: Goes on each seat the vehicle has. The avatar's will be oreinted along the positive X axis when seated.
20
21 3. car_front and car_rear_wheel: Goes on the wheels of the vehicle.
22
23 I stole peices of code from all around these fourms to build this. So sorry if I offend anyone by releasing this.
24
25 car_main
26 // END //

Realistic_Car

Realistic Car Rear Wheel.lsl

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

1
2 //**********************************************
3 //Title: Car Rear Wheel
4 //Author: Aaron Perkins
5 //Date: 2/17/2004
6 //**********************************************
7
8 rotation Inverse(rotation r)
9 {
10 r.x = -r.x;
11 r.y = -r.y;
12 r.z = -r.z;
13 return r;
14 }
15 rotation GetParentRot()
16 {
17 return Inverse(llGetLocalRot())*llGetRot();
18 }
19 SetLocalRot(rotation x)
20 {
21 llSetRot(x*Inverse(GetParentRot()));
22 }
23
24 default
25 {
27 {
28 }
29
30 link_message(integer sender_num, integer num, string str, key id)
31 {
32
33 if(str == "WHEEL_DRIVING")
34 {
35 state driving;
36 }
37
38 }
39
40 }
41
42 state driving
43
44 {
46 {
47 SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO,0,0> ));
48 llSetTimerEvent(0.5);
49 }
50
51 timer()
52 {
53 vector vel = llGetVel();
54 float speed = llVecMag(vel);
56 }
57
58 link_message(integer sender_num, integer num, string str, key id)
59 {
60 if(str == "WHEEL_DEFAULT")
61 {
62 state default;
63 }
64
65 }
66
68 {
69 SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO,0,0> ));
70 llSetTextureAnim(0,ALL_SIDES,0,0,0,0,0);
71 }
72
73 }
74 // END //

Realistic_Car

Realistic Car Seat.lsl

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

1
2 //**********************************************
3 //Title: Car Seat
4 //Author: Aaron Perkins
5 //Date: 2/17/2004
6 //**********************************************
7
8 default
9 {
11 {
12 llSitTarget(<0,0,0.5>, llEuler2Rot(<0,-0.4,0> ));
13 }
14
15 }
16 // END //

Realistic_Car

Realistic Car with remote mod.lsl

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

1
2 //**********************************************
3 //Title: Car
4 //Author: Aaron Perkins
5 //Date: 3/17/2004
6 //**********************************************
7
8 //Feel free to modify these basic parameters to suit your needs.
9 float forward_power = 10; //Power used to go forward (1 to 30)
10 float reverse_power = -15; //Power ued to go reverse (-1 to -30)
11 float turning_ratio = 4.0; //How sharply the vehicle turns. Less is more sharply. (.1 to 10)
12 string sit_message = "Jump In!"; //Sit message
13 string not_owner_message = "You are not the owner of this vehicle ..."; //Not owner message
14
15 //Anything past this point should only be modfied if you know what you are doing
16 string last_wheel_direction;
17 string cur_wheel_direction;
18 integer driving = FALSE;
19
20 default
21 {
23 {
24 llSetSitText(sit_message);
25
26 llSetCameraEyeOffset(<-10.0, 0.0, 2.0> );
27 llSetCameraAtOffset(<10.0, 0.0, 2.0> );
28
29 //car
35 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.0);
38 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.5);
43 }
44
46 {
47 if(!driving)
48 {
49 key agent = llDetectedKey(0);
50 if(agent != llGetOwner())
51 {
52 llSay(0, not_owner_message);
53 }
54 else
55 {
56 llTriggerSound("car_start",1);
57 llMessageLinked(LINK_ALL_CHILDREN , 0, "WHEEL_DRIVING", NULL_KEY);
58 llSleep(.4);
60 llSleep(.1);
62 llSetTimerEvent(0.1);
63 llLoopSound("car_idle",1);
64 driving = TRUE;
65 }
66 }
67 else
68 {
71
73 llSleep(.1);
74 llMessageLinked(LINK_ALL_CHILDREN , 0, "WHEEL_DEFAULT", NULL_KEY);
75 llSleep(.4);
77
79 }
80 }
81 changed(integer change)
82 {
83 if(change & CHANGED_LINK)
84 {
85 key agent = llAvatarOnSitTarget();
86 if(agent)
87 {
88 if(agent != llGetOwner())
89 {
90 llSay(0, not_owner_message);
91 llUnSit(agent);
92 llPushObject(agent, <0,0,50>, ZERO_VECTOR, FALSE);
93 }
94 else
95 {
96 llTriggerSound("car_start",1);
97
98 llMessageLinked(LINK_ALL_CHILDREN , 0, "WHEEL_DRIVING", NULL_KEY);
99 llSleep(.4);
101 llSleep(.1);
103
104 llSetTimerEvent(0.1);
105 llLoopSound("car_idle",1);
106 }
107 }
108 else
109 {
112
114 llSleep(.1);
115 llMessageLinked(LINK_ALL_CHILDREN , 0, "WHEEL_DEFAULT", NULL_KEY);
116 llSleep(.4);
118
120 }
121 }
122
123 }
124
126 {
127 if(perm)
128 {
131 }
132 }
133
134 control(key id, integer level, integer edge)
135 {
136 integer reverse=1;
137 vector angular_motor;
138
139 //get current speed
140 vector vel = llGetVel();
141 float speed = llVecMag(vel);
142
143 //car controls
144 if(level & CONTROL_FWD)
145 {
146 cur_wheel_direction = "WHEEL_FORWARD";
148 reverse=1;
149 }
150 if(level & CONTROL_BACK)
151 {
152 cur_wheel_direction = "WHEEL_REVERSE";
154 reverse = -1;
155 }
156
158 {
159 cur_wheel_direction = "WHEEL_RIGHT";
160 angular_motor.z -= speed / turning_ratio * reverse;
161 }
162
164 {
165 cur_wheel_direction = "WHEEL_LEFT";
166 angular_motor.z += speed / turning_ratio * reverse;
167 }
168
170
171 } //end control
172
173 timer()
174 {
175 if(cur_wheel_direction != last_wheel_direction)
176 {
177 llMessageLinked(LINK_ALL_CHILDREN , 0, cur_wheel_direction, NULL_KEY);
178 last_wheel_direction = cur_wheel_direction;
179 }
180 }
181
182 } //end default
183 // END //

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