Advertisement
AlistairvLearnLab

Distance between avatar and object (use to limit functions by proximity)

Mar 9th, 2021
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. vector objPos;
  2. default
  3. {
  4.    
  5.    
  6.     touch_end(integer num)
  7.     {
  8.        
  9.        objPos = llGetPos();  // get the position of the object  
  10.        key Toucher = llDetectedKey(0);
  11.        
  12.        
  13.        
  14.        
  15.        list tmp = llGetObjectDetails(Toucher,[OBJECT_POS]);
  16.        
  17.        vector avPos = llList2Vector(tmp,0);  // get the position of the avatar who clicked the object.
  18.        
  19.        float distance =  llVecDist(objPos,avPos); // get the distance between the object and the avatar.
  20.        
  21.        if(distance < 10.0 ) // if the distance is less than 10 meters.
  22.        {
  23.            
  24.           llInstantMessage(Toucher,"You are " + (string)llRound(distance) + " meters from the object");
  25.          
  26.           // do other stuff
  27.            
  28.        }
  29.        
  30.        else     // avatars distance is further than 10 meters
  31.        llInstantMessage(Toucher, "You are too far away! Come closer.");
  32.        
  33.        
  34.        
  35.        
  36.        
  37.        
  38.     }
  39.    
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement