CHAPTER 1
CHAPTER 2
CHAPTER 3
CHAPTER 5
CHAPTER 6
CHAPTER 7
CHAPTER 9
CHAPTER 10
CHAPTER 11
CHAPTER 12
CHAPTER 13
CHAPTER 14
CHAPTER 15
APPENDIC
E
S
123
CHAPTER 4
Listing 4.10 causes the moon to rotate on its own axis once every 29.5 days.
Listing 4.10: The Moon's Rotation
default {
state_entry() {
llTargetOmega(llVecNorm(<0,0,1>), 1.0/29.5, 1);
}
}
Listing 4.8 is almost ready to place in the Earth. Make the following changes:
r %PVCMFDIFDLUIBUZPVSgCenterOfRotation is correct for where you put the Earth's position
relative to the sun.
r "EEUXPMJOFTPGDPEFUPcalcCenterOfRotation(), causing the Earth to spin on its own axis
and invoking a timer that calculates the rotation around the sun:
llTargetOmega(llVecNorm(<0,0,1>), 1, 1);
llSetTimerEvent(1.0);
r $IBOHFUIFtouch_start() event handler to be a timer() event handler.
r $PNNFOUPVUUIFDBMMUPllSetLocalRot(). The Earth's rotation is automatically managed by
the Target Omega.
Almost like magic, the Earth will start to spin, and the moon will correctly spin around the Earth,
because its local offset always remains the same, relative to the Earth. Because the Earth's orbit around
the sun is not tied to the sun's internal rotation, you can easily add other planets and have each one
rotate at its own rate.
Wouldn't it be nice if we could simply set the Earth-moon pair to be a single child of the sun in a
nice hierarchical fashion? If we could, we could set the sun to rotate with a Target Omega, and the Earth
would magically stay at the same relative location, with a sum total of 15 lines of code (5 in each prim).
Unfortunately it is not so easy: there is no such thing as hierarchical linking of prims in LSL. Articulation, in
the sense of an articulated arm or leg, is therefore quite challenging in SL; you will find a description of how
to do articulation on the SYW website.
SUMMARY
This chapter focused largely on controlling objectsbringing them into existence and moving them around.
Mastering these techniques may give you the keys to the most important fundamental aspects of scripting
in Second Life. In succeeding chapters, you'll learn a number of advanced techniques for bringing these
creations to life and using the physics model of Second Life. You can combine and extend these scripts in
many ways to gain even greater power over your virtual environment.

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.