Saturday, November 20, 2010

Cartier Watches 61323

sensors intelligent

We have already introduced the sensors, their use and their parameters.
In this short post we will see a very convenient method to make the sensor more "efficient".
We will create a "smart sensor".

Why?
We always said it would be wise to avoid too low values \u200b\u200bfor the rate (ie scan time):

llSensorRepeat ("","", AGENT, 10.0, PI, 1);

In this case the rate is 1, meaning that every second the sensor scans to detect avatars. Not only in some
... cases, we may need an even smaller!

A value such as 0.1 (one tenth of a second) can make such a fluid movement for automatic targeting system (think of a turret, a camera that sets the target)
However, leaving a sensor active all the time with a rate like that can generate lag!


Solution The solution is to create a simple condition in order to speed up the rate only when the avatar is close to the sensor.
It is therefore to calculate the distance to the sensor detected the target, and put our state.

If the distance is less (for example) 15 meters, " override the sensor " with a rate of 0.1, otherwise, with greater distance (> 15) the rate will be set to 10 seconds.
Each script can have only one sensor, then the following always overwrite the previous one.

Here is a practical example, with a sensor that transmits every 10 seconds. If the avatar approaches within 8 feet, then the sensor will transmit every half second (0.5)

////////---- start script /////////////

default
{
state_entry ()
{      
       llSensorRepeat ("", "", AGENT , 30.0, PI, 10);      
    }

    sensor (integer total_number)
    {
     integer distance = ( integer )llVecDist ( llGetPos (), llDetectedPos (0)); / / calculate distance

llSay (0, "transmit");

if (distance \u0026lt;= 8) / / if the distance is less than or equal to 8 feet ....
{            
               llSensorRepeat ("", "", AGENT , 30, PI, 0.5);
            }
        else if ( distance > 8) //altrimenti......
            {
              llSensorRepeat ("", "", AGENT , 30, PI, 10);
             }      
}}


////////---- ///////////////// end script /////

llVecDist function () calculates the distance between two vectors: in our case between the sensor position and noted that the avatar.
first tried to keep a distance ... what happens if you approach within 8 feet?

0 comments:

Post a Comment