CHAPTER 5
134
BUILDING
SENSORS
DETECTION
WITH
COLLISIONS
USING
GREETERS TO
WELCOM E
VISITORS
SUMMARY
TABLE 5.1: QUERY PARAMETERS FOR llGetObjectDetails()
FLAG DESCRIPTION ALTERNATIVE FUNCTION
OBJECT_NAME
Gets the object's name as a string up to 63 characters long.
llKey2Name()
llDetectedName()
OBJECT_DESC
Gets the object's description (empty if avatar) as a string up to
127 characters long.
OBJECT_POS
Gets the object's position as a vector in region coordinates.
llDetectedPos()
OBJECT_ROT
Gets the object's rotation as a rotation.
llDetectedRot()
OBJECT_VELOCITY
Gets the object's velocity as a vector.
llDetectedVel()
OBJECT_OWNER
Gets an object's owner's UUID as a key. If group-owned or
avatar, a NULL_KEY is returned.
llDetectedOwner()
llGetOwnerKey()
OBJECT_GROUP
Gets the prims's group UUID as a key. If avatar, a NULL_KEY is
returned.
llDetectedGroup()
OBJECT_CREATOR
Gets the object's creator UUID as a key. If avatar, a NULL_KEY
is returned.
llGetCreator()
DET
E
CTION WITH COLLISIONS
In many situations a collision sensor is a cheaper way to detect things. You can place filters on the
collision events with llCollisionFilter(), which sets the name and/or key of the item to
detect and indicates whether to ignore or accept the collision. You can play sounds on collision via
llCollisionSound(), and use llPassCollisions() to control whether child prims tell the root
prim about collisions. The details are sketched in Table 5.2.
TABLE 5.2: COLLISION FUNCTIONS
FUNCTION BEHAVIOR
llCollisionFilter(string name,
key id, integer accept)
Filter collision events. Boolean accept; FALSE means reject collisions
from name, and TRUE means accept them.
llCollisionSound(string sound,
float volume)
Play sound on collisions instead of the default. The sound parameter
may be the name of a sound in inventory, a built-in sound, or the UUID
of a sound anywhere. If sound is an empty string ("") no sound is played.
volume ranges from 0.0 to 1.0.
llPassCollisions(integer pass)
Pass collisions to parents. If the parent is using a phantom volume detect,
then the child prim will not receive collision events and the child will also
become phantom.
Three events can be triggeredcollision(), collision_start(), and collision_
end()each taking the single parameter numDetected. Avatars and physical objects will trigger
collisions. Attachments and nonphysical objects won't.
CHAPTER 1
CHAPTER 2
CHAPTER 3
CHAPTER 4
CHAPTER 6
CHAPTER 7
CHAPTER 9
CHAPTER 10
CHAPTER 11
CHAPTER 12
CHAPTER 13
CHAPTER 14
CHAPTER 15
APPENDIC
E
S
135
CHAPTER 5
collision_start(integer numDetected) {}
collision(integer numDetected) {}
collision_end(integer numDetected) {}
Events in the collision family are invoked in an object after an avatar or physical object collides with it.
collision_start() is triggered when the collision starts; collision() is triggered periodically
while the objects are colliding; collision_end() is triggered when the collision ends. Compare
to the touch() and land_collision() families of events in Chapters 2 and 7, respectively.
Additional documentation can be found on the SYW website.
numDetected — The number of objects or avatars that have collided.
EVENT
DEFINITION
Collisions are a nice, simple way to detect whether there's an avatar nearby, but the avatar will collide
with the object, and that may not be the effect you are after. However, because you can't simply make the
objects phantom so that avatars can walk through them without colliding (phantom objects don't trigger
collisions), another useful function is llVolumeDetect(), which can make the object phantom but still
trigger collision events when something enters the object.
llVolumeDetect(integer detect)
If detect is TRUE, the object becomes phantom but triggers collision_start() and
collision_end() events when other objects enter or leave the object. It will not trigger
collision() events. When FALSE, the object does not become phantom and thus can trigger all
three event types: collision(), collision_start(), and collision_end()
*
. This function
must appear in the root prim.
detect — Enables or disables phantom collision detection.
* The FALSE case makes nonphysical objects react to collisions as if they were physical. While useful, this
is undocumented behavior, so be careful if you use this feature.
DEFINITION
In comparison to llSensorRepeat(), the volume detector is a lot less expensive in terms of
computational resources, and you don't need to worry about delay. (The sensor may not catch an object if it
moves too quickly through the sensor zone.) You can use any arbitrary object (any shape, size, etc) to hold the
volume detector. That's cool because llSensorRepeat() will sense only in conical slices from spheres.
Whether the sensor or the volume detector is better for your situation depends on a variety of
factors. Table 5.3 summarizes the most common situations.

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.