How to make a realistic movement in Second Life™ -
Making the fins move
This section will show you how to add the script that makes the tail
and fins move in our blue whale:
Add the following script to all of the fins, and to the tail section
that hangs out. The simplest way to do this is to put the script into
your inventory, and drag and drop the script into each child prim.
You must select the whale in Edit mode (Ctrl-3), then check the box
called "Edit Linked Parts". Then click each tail surface and drag
the script into the Contents tab.
This script is used to send the prim coordinates to a master control
script, once. After you have taught the master control script
how to move the fins, the script can be deleted by clicking a button
on the master control scripts menu.
The script requires that some variables be available from anywhere
in the program. These variables are 'global' variables. The first
part of the script contains them.
Download
integer linkchannel = 5001; // for recording purposes
vector vLastpos; // the last position
rotation rLastrot; // the last rotation
Now that we have the globals defined, it is time for the actual code.
All Second life LSL scripts must have a default{..} procedure.
Inside that default{..} , between the starting { and ending } braces,
is the code. The first function we will use is the on_rez() function.
This function will be called by the server whenever our whale is rezzed.
We will use this to reset the script with the llResetScript() system
call. The forces the script to start 'at the beginning'.
default
{
on_rez(integer p)
{
llResetScript();
}
A link message is a prim-to-prim message. They
are generated by llMessageLinked commands in the main script.
When the main script runs the following code:
llMessageLinked(LINK_SET,0,"Set",NULL_KEY); // part of another script
The link_message will be executed in the child script, and the string
'msg' will become 'Set'.
// accept messages from the main script
link_message(integer sender_num, integer num, string msg, key id)
{
The script we will write will look for any of 3 possible message: Set,
Remove, and Reset. If the message is Set, the script will wait
for up to 3 seconds. This delay is generated so that the master
control script can handle more prims. Without a delay, every
script in every prim would all talk at the same time, and queue up a
large amount of traffic. If the number of messages was > 64, then
some coordinates would get dropped. The Set code also gets the
current rotation and current position. If they are different i.e.,
the prim has moved), the new coordinates are stored and the script sends
to the control script a message with the changed position and rotation
embedded in it. The master control script will remember
those coordinates for later playback.
if (msg == "Set") // Set records the current prim rot and pos.
{
llSleep(llFrand(3.0));
vector vPos = llGetLocalPos();
rotation rRot = llGetLocalRot();
if (vPos != vLastpos || rRot != rLastrot)
llMessageLinked(LINK_ROOT, linkchannel, (string) vPos + "|" + (string) rRot, "");
vLastpos = vPos;
rLastrot = rRot;
}
If the message is 'Remove', then you have finished recording the coordinates.
The script will then delete itself.
else if (msg == "Remove") // deletes the script from the child to help with lag
{
llRemoveInventory(llGetScriptName());
}
If the message is 'Reset', then the script sets the coordinates to zero.
because it is highly unlikely that the child prim center script is exactly
the same as the root prim center, this makes the script report all child
prims when the Set command is receive.
else if (msg == "Reset") // set the coords to some rare value so the prim
// will have been seen to have moved
{
vLastpos = <0,0,0>;
rLastrot = <0,0,0,1>;
}
The 'All' command is a combination Reset and Set. When issued, the child
prim reports it's coordinates.
else if (msg == "All") // dump the current pos and rot to the server
{
vector vPos = llGetLocalPos();
rotation rRot = llGetLocalRot();
llSleep(llFrand(3.0));
llMessageLinked(LINK_ROOT, linkchannel, (string) vPos + "|" + (string) rRot, "");
}
}
}
Next - > Part 5-
Fish spray script
- making Make your whale spray water
Back to the Best Free Tools in Second Life and OpenSim.