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
Boat OpenSim JetSki  

OpenSim JetSki

TSim Jet Ski

Category: Boat
By : Thomas Ringate
Created: 2015-06-11 Edited: 2015-06-11
Worlds: OpenSim

the Zip file

Download all files for OpenSim JetSki
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Script.lsl
1 //:License: GPLV2
2 //:VERSION:1.02
3
4 // XEngine:lsl
5 // TSim Jet Ski V1.02
6 // Licensed under the GPLv2.
7 // From the OsGrid Forums:
8 // http://forums.osgrid.org/viewtopic.php?f=5&t=5486
9
10 // Tested as working with the bullet physics engine.
11 // This script detects the region edge and stops the jet ski from crossing the border. It detects the size of a var region.
12 // The four arrow keys steer the jet ski.
13 // The jet ski will detect shore and come to a near stop.
14 // If you beach the jet ski you are going to have to drive it back in the water. It will move very slowly on land.
15 // Version V1.02
16 // Initial release
17 //
18 //==== G L O B A L V A R I A B L E D E C L A R A T I O N ====
19
20 integer xlimit; // region size limit
21 integer ylimit; // region size limit
22 integer gRun; //Engine status
23 integer gGuard = 3; // the distance to detect the edge of the region boundary
24 string gDrivingAnim = "motorcycle_sit"; // sit animation for the jet ski
25 vector gSitTarget_Pos = <-0.43,0.03,0.69>; // sit position (will need to be adjusted for your jet ski)
26 vector vTarget; // vehicle position
27 key gAgent; // the key for the siting avatar
28 float fWaterLevel; //region water level
29 float gSpeed = 35.0; // forward speed of the jet ski
30 float gForwardThrust; // variable for forward thrust
31 float gReverseThrust = -15; // reverse thrust which is it's reverse speed
32 float gTurnMulti=1.012345; // used for the AngularMotor
33 float gTurnRatio; // used for the AngularMotor
34
35 init_engine(){
36 gRun = 0; //Engine off
37 vector gSitTarget_Rot = llRot2Euler( llGetRootRotation() ); // SIT TARGET IS BASED ON VEHICLE'S ROTATION.
38 llSitTarget(gSitTarget_Pos, llEuler2Rot(DEG_TO_RAD * gSitTarget_Rot));
39 llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_NONE]);
40 }
41
42 init_followCam(){
44 [
45 CAMERA_ACTIVE, 1, // 0=INACTIVE 1=ACTIVE
46 CAMERA_BEHINDNESS_ANGLE, 2.5, // (0 to 180) DEGREES
47 CAMERA_BEHINDNESS_LAG, 0.3, // (0 to 3) SECONDS
48 CAMERA_DISTANCE, 6.0, // ( 0.5 to 10) METERS
49 PITCH" title="View Definition" class="tooltip">CAMERA_PITCH, 12.0, // (-45 to 80) DEGREES
50 CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
51 CAMERA_POSITION_LAG, 0.0, // (0 to 3) SECONDS
52 CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) METERS
53 CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
54 CAMERA_FOCUS_LAG, 0.0, // (0 to 3) SECONDS
55 CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) METERS
56 CAMERA_FOCUS_OFFSET, <0.0,0,0> // <-10,-10,-10> to <10,10,10> METERS
57 ]);
58 llForceMouselook(FALSE); // make sure mouse look is off
59 }
60
61 set_engine(){
63 // default rotation of local frame
64 llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, <0.00000, 0.00000, 0.00000, 0.00000>); // <0.00000, 0.00000, 0.00000, 0.00000>
65 // linear motor wins after about five seconds, decays after about a minute
66 llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.90);
68 // least for forward-back, most friction for up-down
70 // uniform angular friction (setting it as a scalar rather than a vector)
72 // agular motor wins after four seconds, decays in same amount of time
74 llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.10);
75 // halfway linear deflection with timescale of 3 seconds
78 // angular deflection
81 // somewhat bounscy vertical attractor
84 // hover
89 // weak negative damped banking
93 // remove these flags
97 // set these flags
102 }
103
104 default {
106 {
107 vector vTarget = llGetPos();
108 vTarget.z = llGround( ZERO_VECTOR );
109 fWaterLevel = llWater( ZERO_VECTOR );
110 if( vTarget.z < fWaterLevel )
111 {
112 vTarget.z = fWaterLevel;
113 llSay(0,"Ready to go!");
114 }
115 else
116 {
117 llSay(0,"I work best in water!");
118 }
119 llSetRegionPos(vTarget + <0,0,0.1>);
120 init_engine(); // initialize the engine
121 state Running; // switch to the running state
122 }
123 }
124
125 state Running{
126
128
129 }
130
131 on_rez(integer param) {
133 }
134
135 changed(integer change){
136 if((change & CHANGED_LINK) == CHANGED_LINK){
137 gAgent = llAvatarOnSitTarget(); // get the sitting avatars key
138 if(gAgent != NULL_KEY){ // we have a driver
140 llSetStatus(STATUS_ROTATE_Y,TRUE);
141 llSetStatus(STATUS_ROTATE_Z,TRUE);
142 set_engine(); // set the engine parameters
143 vector regionsize = osGetRegionSize(); // get the max size of the region dimentions
144 xlimit = (integer)regionsize.x - gGuard; // set the region top limit
145 ylimit = (integer)regionsize.y - gGuard; // set the region top limit
147 gRun = 1; // Engine on
148 }
149 else { // driver got off
150 llSetStatus(STATUS_PHYSICS, FALSE); // turn physics off
151 gRun = 0; // Engine off
152 init_engine(); // initialize the engine
153 llStopAnimation(gDrivingAnim);
154 llPushObject(gAgent, <3,3,21>, ZERO_VECTOR, FALSE);
157 llSetCameraParams([CAMERA_ACTIVE, 0]);
158 llSetText("",<0,0,0>,1.0);
159 }
160 }
161 }
163 if(perm) {
165 init_followCam();
166 llStartAnimation(gDrivingAnim);
167 llSleep(1.5);
168 }
169 }
170
171 control(key id, integer held, integer change){
172 if(gRun == 0){
173 return;
174 }
175 integer reverse=1;
176 vector vel = llGetVel();
177 vector speedvec = llGetVel() / llGetRot();
178 vector AngularMotor;
179 gTurnRatio = 1.5;
180 vTarget = llGetPos(); // get jet ski position
181 if(held & CONTROL_FWD){
182 reverse=1;
183 gForwardThrust = gSpeed;
184 // if near region edge, slow down, and veer to the right
185 if(vTarget.x > xlimit || vTarget.x < gGuard || vTarget.y > ylimit || vTarget.y < gGuard) {
187 gForwardThrust = 3; // slow us down
188 if(vTarget.x > xlimit) vTarget.x = xlimit;
189 if(vTarget.x < gGuard) vTarget.x = gGuard;
190 if(vTarget.y > xlimit) vTarget.y = ylimit;
191 if(vTarget.y < gGuard) vTarget.y = gGuard;
192 reverse = -1;
193 llWhisper(0, "Approaching sim edge, turn away...");
194 }
195 if(vTarget.z > (fWaterLevel + 1.4)) {
196 gForwardThrust = 2; // slow us down
197 }
199 llSetPos(vTarget);
200 }
201
202 if(held & CONTROL_BACK){
204 gTurnRatio = -2.0;
205 reverse = -1;
206 }
207
208 // vector AngularMotor;
209 AngularMotor.y = 0;
210 if(held & (CONTROL_ROT_RIGHT)){
211 AngularMotor.x += ((gTurnRatio/gTurnMulti)*1);
212 AngularMotor.z -= ((gTurnRatio*gTurnMulti)/1);
213 }
214
215 if(held & (CONTROL_ROT_LEFT)){
216 AngularMotor.x -= ((gTurnRatio/gTurnMulti)*1);
217 AngularMotor.z += ((gTurnRatio*gTurnMulti)/1);
218 }
220 }
221 }

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