llSensor(string name, key id, integer type, float range, float arc)
Performs a single
sensor scan for
name and
id with
type (
AGENT,
ACTIVE,
PASSIVE, and/or
SCRIPTED) within
range meters and
arc radians of forward
vector (along x-
axis).
PI radians will search in all directions.
name and
id need no filter. If
name is a
null string (i.e. "
"),
llSensor() will look for
objects with any name. If
id is the
NULL_KEY, then
llSensor() will look for objects with any
id. The limit of
range is 96m.
Values greater than 96m will be accepted but will be treated as 96m. Note that a
range of
0.0 does perform a scan.
Compare with
llSensorRepeat, which allows a recurring sensor scan.
Raises the
sensor event when it finds a match, and
no_sensor when it finds none; see
sensor for an example.
Constants for
type:
[1] Active: the script is running and currently doing something. A basic default script that is running may not be active but a script that has a command monitoring, like with
llListen, will always be active. "Active" means more
sim resources are being used.
[2] Inactive: the script is running and awaiting an event and isn't doing any monitoring (like
llListen). Very little sim resources are being used.
[3] Running scripts may be active or inactive (or, to use
SL lingo, "active" or "passive").
Notes
- Values can be combined to search in multiple categories using bitwise OR (|). For example, llSensor("", NULL_KEY, AGENT | ACTIVE, 25, PI) would search for both agents and physical objects.
- After detecting a PASSIVE, ACTIVE, and/or SCRIPTED object, llDetectedType may be used to check the ACTIVE flag (physical) and the PASSIVE flag (non-physical, even if the object contains an active script). The SCRIPTED flag always seems to only detect/apply to active scripts. So it seems llSensor and llDetectedType use the PASSIVE and ACTIVE flags differently. See also ObjectType for more info about types of objects to detect.
- The sensors detect objects only if their center falls in the detection cone (see below). This makes it harder to use sensors for pathfinding, especially avoiding big objects like walls.
- Sensors cannot be used to detect another object's child prims.
- llSensor and llSensorRepeat will not detect the object that contains them. This also applies to attachments--they won't detect the agent they're attached to unless the sensor script is within a child prim.
- The name parameter is case-sensitive, and will not accept partial names. For example, an object by the name Object will only match when the name parameter is Object, not object or Obj.
- llSensor only detects objects within the same Sim. If you need to detect object's positioned in adjacent Sims, use llSensorRepeat.
- The SCRIPTED flag combines strangely with the others, see below.
Combining SCRIPTED and Other Flags
Combining the
SCRIPTED flag with others can lead to somewhat unintuitive results (this is because AGENT, PASSIVE and ACTIVE behave inclusively. SCRIPTED is not inclusive and will exclude non-scripted targets, like avatars, from the detected set):
- SCRIPTED will detect active scripts, or moving physical objects containing a script (active or not).
- AGENT | SCRIPTED will detect active scripts, or moving physical objects containing a script (active or not); this will not detect agents!
- ACTIVE | SCRIPTED will detect active scripts, or moving physical objects that contain a script (active or not); this will not detect moving physical objects that are not scripted.
- PASSIVE | SCRIPTED will detect active scripts, non-scripted non-physical objects, and physical objects containing a script (active or not); it does not detect stationary physical objects that are not scripted.
Detection Cones (Arc)
If arc is
x radians, the
sensor will look for
x radians around the object's forward vector (which is the object's
local X
axis, positive direction), so the actual sweep of the search is
2 * x radians, and thus
PI radians will search all around the object.
In SL terms, the sensor sweep area is a dimpled sphere, with the range defined by the sphere's radius and the arc by the dimple itself.
Sensors placed in
attachments will use the direction the avatar is facing as their forward vector. In
mouselook, this means that it will be wherever the avatar is looking, while out of mouselook, this means whichever way the avatar is pointing. This does not include where the avatar's head is pointing, or what
animation the avatar is doing, just the direction the avatar would move in if you walked forward. This is the case, regardless of where the object is attached.
Sensor Visualisation
This one has arc = PI / 4 and thus scans a radius of 45 degree around the x-axis:
video (MPEG, 630KB) of it rotating
| For arc = PI_BY_TWO (90 degrees around the x-axis, or a half sphere--hemisphere):
|
And for arc = PI (180 degrees around the x-axis, which means a sphere):
|
Q: Can I use sensors to detect attachments?
A: No, but you can use llGetAgentInfo to determine whether or not an avatar has attachments, and whether or not they're scripted, though not how many attachments they have, where they're attached, nor what they are.
Q: How can I use a sphere prim to determine sensor radians?
A: Using just the Begin dimple, keeping the end 1.0, the math would be: radians = PI - (PI * dimple);
This article wasn't helpful for you? Maybe the
related article at the LSL Portal is able to bring enlightenment.
Functions |
Sensors