The use of sensors is widely used in SL, from radar, surveillance systems and the follower (objects that follow an avatar or other object).
The sensor is driven by functions
llSensor
() and
llSensorRepeat
() which will be triggered when the sensor detects a target within established. On the contrary, the event no_sensor () will activate when the sensor does not detect any target in his range.
Since the functions are very similar, we will use as an example
llSensorRepeat (), since getting a parameter in addition: the interval of each scan.
The parameters are supported:
-
string name: the name of the avatar or object to be detected
- key id: uuid of the avatar or object to be detected - integer type: there used to be one of the following flags: (AGENT, AGENT_BY_LEGACY_NAME, AGENT_BY_USERNAME, ACTIVE, PASSIVE, and / or scripted) -
float range: the range in meters (the maximum radius is 96mt) - float
arc: the angle formed between the axis X
local object and the target (we shall soon see) -
float range: The range in which the sensor scans (eg every 3 seconds) Let's see in action with a simple test script: default {
state_entry () {
llSensorRepeat ("","", AGENT, 10.0 , PI, 5.0);
/ / 10metres radius, angle PI, every 5 seconds
} sensor (integer num_detected)
/ / when it encounters ...... { llSetColor (\u0026lt;0, 1, 0>, ALL_SIDES) / / becomes Green
if ( llDetectedKey (0) == llGetOwner ()) / / if the target is found the owner (you ) says ... {
llDetectedName (0));} ; else
/ / otherwise, to any other, says ... {
llSay (0, "Hello," + llDetectedName
(0));}
}
no_sensor
()
/ / if no notes .....
{
llSetColor ( \u0026lt;1, 0, 0>, ALL_SIDES)
/ / turn red.
}} This example script performs a scan of 10 yards every 5 seconds, and the field of detection is almost spherical (angle PI). I also wrote that the inner sphere should turn green and say the name of the Owner or any other resident is detected. Inside the event sensor () I could add anything else (such as a sound, a movement, a text). If within 10 meters there is nothing, the first extension turns red. If more
avatars are within the range, the sensor will always pick the closest.
is the classical case, if the angle is PI:
are 10 meters away from the inner sphere is red ...
if by hand for example and I'm six feet, the inner sphere will be green:
What happens if you halve the IP and I do become a PI / 2?
The scan will take place within a hemisphere, and the direction will be given to the local X axis (red) of the first.
If I go within 10 meters (green ray), but I'm behind the red ball, is not detected!
(The ball inside is always red, but they are 6 meters). Virtually the white area is the field where I can be detected.
I try to halve again? port: PI / 8: this time the beam will become more and more the shape of a cone, and I, even though close to the sensor, are excluded, however, if not in perfectly within the white field (I do not detect the ball, remaining red).
some rules to make best use of the sensors. - It 's good to keep in mind that the sensors are among the functions that can cause a lot of lag on server.For reduce the excessive load, it is important remember not to give too small values \u200b\u200bof the rate (in our case 5.0). - When you can, you should use the llSensorRemove () to remove the sensor if we do not need any. - The sensor starts from the exact center of the prim prim ren .. use does not increase the range.
- There can be only one sensor to the script.
- flags for the type seen above: ACTIVE, PASSIVE, scripted, respectively refer to physical prim, scripted and non-physical (type of target can be observed, in addition agents - ie avatar) Soon we'll see how it is possible to build a tower or a camera that scans the environment and the avatar pointed tip.