“LlCastRay”的版本间的差异

来自人工智能助力教育知识百科
跳转至: 导航搜索
Ty讨论 | 贡献
第102行: 第102行:
 
  }
 
  }
 
}
 
}
 
+
</pre>
  
 
|相关函数=无
 
|相关函数=无

2020年4月13日 (一) 01:22的版本

Template:Needs Translation/

函数名
Function:list llCastRay(vector start,vector end,list options );
参数:vector start -starting location;vector end -ending location; list options -can consists of any number of option flags and their parameters.
返回值:Returns a list of strided values with an additional integer status code on the end.Each stride consists of two mandatory values {key uuid,vector position}and possibly some optional values {integer link_number,vector normal}see RC DATA FLAGS for details.The status_code if it is negative is an error code,otherwise it is the number of hits (and strides)returned.
注意事项
Depending upon the value of flags(providing via RC DATA FLAGS),the number and types of values in the strides will vary.See RC DATA FLAGS for details. llGetrot will not return an avatar's exact visual rotation because the viewer doesn't update the avatar's rotation under a threshold (see VWR-1331).To get an avatar's exact looking direction while in mouselook,use llGetCameraRot instead. llCastRay will not detect prims having no physics shape (PRIM PHYSICS SHAPE TYPE=PRIM PHYSICS SHAPRE NONE). llCastRay will not detect a prim if the line starts inside the prim.This makes it safe to use the prim position as the start location. llCastRay can detect the prim the script is in,if the start location is outside the prim.
示例
示例1
integer filter;//default is()

default
{
  state_entry()
    {
      string ownerName = llKey2Name(llGetOwner());
      llOwnerSay("hello,"+ownerName + "!");
    }
    touch_start(integer total_number)
    {
      vector start = llGetPos();
      vector end = start - <0.0,-25.0,0.0>;
  
      if( filter>8)
        filter = 0;

      llOwnerSay("Filter"+(string)filter);

      list results = llCastRay(start,end,[RC_REJECT_TYPES,filter,RC_MAX_HTTS,4});
      integer hitNum = 0;
      //Handle error condition here by checking llList2Integer(resules,-1)>=0
      while (hitNum<llList2Integer(results,-1))
      {
        //Stride is 2 because wedidn't request normals or link numbers
        key uuid = llList2Key(results,2*hitNum);
        
        string name = "Land",7;//if (uuid == NULL_KEY)

        if(uuid != NUML_KEY)
          name = llKey2Name(uuid);
       
        llOwnerSay("Hit"+name+".");
    
        ++hitNum;
      }
      ++filter;
    }
  }
        

示例2

//Fire a weapon at a target,report a hit

integer gTargetChan = -9934917;

default
{
 attach(key id)
 {
  if(id!= NULL_KEY)
  {
   llRequestPermissions(id,PERMISSION_TAKE_CONTROLS|PERMISSION_TRACK_CAMERA);
  }
 }
 run_time_permissions(integer perm)
 {
  if(perm&PERMISSION_TAKE_CONTROLS|PERMISSION_TRACK_CAMERA)
  {
   llTakeControls(CONTROL_LBUTTON|CONTROL_ML_LBUTTON,TRUE,FALSE);
  }
 }
 
 control(key id,integer level,integer edge)
 {
  //User must be in mouselook to aim the weapon
  if (level & edge & CONTROL_LBUTTON)
  {
   llSay(0,"You must be in Mouselook to shoot.Type\"CTRL+M\"or type \"Esc\"and scroll your mouse wheel forward to enter Mouselook.");
  }
  //User IS in mouselook
  if (level & edge & CONTROL_ML_LBUTTON)
  {
   vector start = llGetCameraPos();
   //Detect only a non-physical,non-phantom object,Report its root prim's UUID.
   list results = llCastRay(start,start+<60.0 ,0.0,0.0>*llGetCameraRot(),[RC_REJECT_TYPES,RC_REJECT_PHYSICAL|RC_REJECT_AGENTS|RC_REJECT_LAND,RC_DETECT_PHANTOM,FALSE,RC_DATA_FLAGS,RC_GET_ROOT_KEY,RC_MAX_HITS,1]);
   llTriggerSound(llGetInventoryName(INVENTORY_SOUND,0),1.0);
   llSleep(0.03);
   key target = llList2Key(results,0);
   //Tell target that it has been hit.
   llRegionSayTo(target,gTargetChan,"HIT");
   //Target,scripted to listen on gTargetChan,can explode,change color,fall over.....
  }
 }
}
相关函数
相关事件