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
Animation swimming_fish  

swimming_fish

swimming fish.lsl

Category: Animation
By : Cubey Terra
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for swimming_fish
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. swimming_fish_1.lsl
1
2 // SWIMMING AROUND SCRIPT
3 // Cubey Terra
4 // May 27 2006 - First verion of Linerunner script.
5 // June 19 2006 - Adapted to torpedo from Linerunner script.
6 // July 16 2006 - Adapted for a virtual life experiment.
7 // Aug 27 2006 - Adapted for simple swarming prims.
8 // April 19 2007 - Adapted for non-swarming fish
9
10
11
12
13 // CONSTANTS
14 float BLARG = 2.0; // provides a bit of randomness to fish targeting
15
16 string targetName;
17 integer swarming = FALSE;
18
19 vector START_SIZE = <0.1,0.1,0.1>;
20 float BUOY_NEUTRAL = 0.98; // vehicle buoyancy parameter.
21 float THRUST_FACTOR = 0.5; // xLinearMotor = throttle * THRUST_FACTOR * energy
22 integer THROTTLE_MAX = 2;
23 float TIMER_INT = 0.25;
24 string SND_DIE = "2cf64119-69e6-48e1-8d43-7e66f24f38d7";
25 rotation REF_FRAME = <0.00000, -0.70711, 0.00000, 0.70711>; // vehicle reference frame
26 float ANG_MOTOR = 2;
27
28 //integer TURN_SEC = 2; //# seconds between turns
29 float RANGE = 96;
30 integer CHAT_CHANNEL = 10;
31
32
33
34 // VARIABLES
35 integer running;
36 float maxAlt = 16;
37 integer throttle;
38 float xLinearMotor;
39 float zLinearMotor;
40 vector pos;
41 vector targetPos = <128,128,128>;
42 float mass;
43 integer listentrack;
44 float buoyancy;
45
46
47
48 setVehicleParams()
49 {
54 llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.5 );
58 llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 5);
80 );
81 }
82
83
84
85 startListen()
86 {
87 if(listentrack)
88 {
89 llListenRemove(listentrack);
90 listentrack = 0;
91 }
92 llListen(CHAT_CHANNEL, "", "", "");
93 }
94
95
96
97 init()
98 {
99 llSitTarget(<0,0,0.1>, REF_FRAME); // while not a vehicle, it might be fun to ride :)
101 llSetStatus(STATUS_DIE_AT_EDGE | STATUS_PHANTOM, TRUE);
102 setVehicleParams();
103
104 targetName = llGetObjectName(); // swarm after others of my type, if present
105 buoyancy = BUOY_NEUTRAL;
106 startListen();
107 mass = llGetMass();
108 throttle = 1;
109 targetPos = llGetPos();
110 llSetTimerEvent(TIMER_INT);
111 }
112
113 setMotor()
114 {
115 throttle = (integer)(llRound(llFrand(THROTTLE_MAX)) + 1);
116
117 // calculate current thrust based on amount of available steam.
118 xLinearMotor = throttle * THRUST_FACTOR;
120 }
121
122 setBuoyancy()
123 {
124 if(pos.z > maxAlt) // if above maxAlt
125 {
126 buoyancy = BUOY_NEUTRAL/(pos.z - maxAlt); // buoyancy is reduced proportionally to height above max alt
127 }
128 else
129 {
130 buoyancy = BUOY_NEUTRAL;
131 }
133 }
134
135 lookAt()
136 {
137 mass = llGetMass();
138 float strength = mass;
139 float damping = strength/3;
140 llLookAt(targetPos, strength, damping);
141 //llSetText("Target: "+(string)targetPos,<1,1,1>,1);
142 }
143
144
145
146 default
147 {
148 listen(integer sender, string name, key id, string message)
149 {
150 if(message == "die")
151 {
152 llTriggerSound(SND_DIE,1);
153 llDie();
154 }
155 else if(llSubStringIndex(message, "target") == 0)
156 {
157 // target,<fish name>,x,y,z
158 list data = llCSV2List(message);
159 string dataname = llList2String(data,1);
160 vector datapos;
161 //llOwnerSay(llList2CSV(data));
162 if(dataname == llGetObjectName())
163 {
164 datapos.x = llList2Float(data,2);
165 datapos.y = llList2Float(data,3);
166 datapos.z = llList2Float(data,4);
167 maxAlt = datapos.z;
168
169 vector offset;
170 offset.x = llFrand(BLARG);
171 offset.y = llFrand(BLARG);
172
173 targetPos = datapos + offset;
174 running = TRUE;
175 }
176 }
177
178 }
179
181 {
182 init();
183 }
184
185 on_rez(integer num)
186 {
188 }
189
190
191 timer()
192 {
193 if(running)
194 {
196 pos = llGetPos();
197 setMotor();
198 setBuoyancy();
199 lookAt();
200 }
202
203 }
204 }
205 // END //

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