CHAPTER 6
A WATERFALL
SHAPING THE
LAND BY
TERRAFORMING
LAND
SECURITY
ARE YOU ON
THE LIST?
LAND
INFORMATION
FUNCTIONS
SUMMARY
142
A WATERFALL
New scripters may not realize that water (pools, rivers, rainstorms, waves) is not “real” in the sense
of being interactive or reactive to its surrounding environment. Thus, if you want water, you have two
options:
r 5FSSBGPSNJOHUPNBLFUIFPGGJDJBMSL water level higher than the ground level. Terraforming is
covered in the “Shaping the Land by Terraforming” section of this chapter.
r $SFBUJOHPCKFDUTUIBUBDUBTXBWFTPSXBUFSDBTDBEFTBOEBQQMZJOHUFYUVSFBOJNBUJPOBOEQBSUJDMF
effects to them. This approach is used in this section.
At SYW HQ, we have a water mill that is powered by the waterfall falling from the cliff behind. Figure
6.1 shows the completed mill from a long view.
Figure 6.1: A water mill with working wheel,
gears, and turbulent waters
You have probably seen fountains galore in Second Life, and the technical approach is simple and
consistent. You simply choose an appropriate water texture (Linden Lab supplies an excellent assortment
in your free Library folder), then animate it with a recipe such as the one in Listing 6.1. This script provides
the animation in the pool below the waterfall, and is sufficiently convincing for the human eye to perceive
what appears to be real water.
Listing 6.1: Water Animation
default {
state_entry(){
llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, ALL_SIDES, 1, 1, 1.0, 1.0, 0.05);
}
}
llSetTextureAnim() is intended to use textures with multiple frames embedded; it usually plays
them as frames like in a movie. This function is described in detail in the “Texture Animation” section of
$IBQUFSi4QFDJBM&GGFDUTu5IJTMJTUJOHDPNCJOFTSMOOTH and LOOP in the first parameter (mode) so
the water appears to flow continually in the x direction. LOOP makes the animation play over and over,
while SMOOTH slides from one frame to the next. The number of rows and columns is set to 1 because
there’s only a single logical frame to this texture, and likewise for the length.
CHAPTER 1
CHAPTER 2
CHAPTER 3
CHAPTER 4
CHAPTER 5
CHAPTER 7
CHAPTER 9
CHAPTER 10
CHAPTER 11
CHAPTER 12
CHAPTER 13
CHAPTER 14
CHAPTER 15
APPENDIC
E
S
143
CHAPTER 6
This is sufficient for the catch pool, but the parts of the waterfall itself are slightly more complex (and
visually interesting as a result). Note in Figure 6.2 that the waterfall consists of three nearly hollow vertical
cylinders tapered toward their tops. These are joined to a horizontal cylinder at the top of the falls.
Figure 6.2: Multipart waterfall composed of
tapered flexiprim cylinders
Using the animation described in Listing 6.2 would be visually interesting enough, and, given the fact
that the individual cylinders are flexible (flexiprims), could be visually convincing. Real waterfalls hardly ever
drop at constant rates, however, so Listing 6.2 attempts to add further realism by varying the animation
rate for each of the three cylinders over time.
Listing 6.2: Improved Water Animation
float randBetween(float min, float max) {
return llFrand(max - min) + min;
}
default {
state_entry() {
float rand = llFrand(10.0);
llSetTimerEvent(rand);
}
timer() {
state fallingWater;
}
}
state fallingWater {
state_entry() {
float rate = randBetween(0.05, 0.35);
llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, ALL_SIDES, 1, 1, 1.0, 0.0, rate);
llSleep(1.5);
state default;
}
}
The default state sets a random timer event using the llFrand() function to return a random
floating-point number between 0.0 and 10.0. When the timer elapses, control transitions immediately
to the fallingWater state, the state_entry() event handler chooses a random number to
approximate a reasonable flow rate in harmony with the rotational rate of the water wheel. It selects the
random number and then initiates the animation with its new variable rate.

Get Scripting Your World: The Official Guide to Second Life® Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.