纳金网

标题: (转)自动判断路径障碍的寻路功能_代码 [打印本页]

作者: 她。    时间: 2012-6-15 17:42
标题: (转)自动判断路径障碍的寻路功能_代码



   

     
    void Update () {

     
            Ray ray = camera.ScreenPointToRay(target.position);



        



/*Physics.Raycast 光线投射

static function Raycast (origin : Vector3, direction : Vector3, distance : float = Mathf.Infinity, layerMask : int = kDefaultRaycastLayers) : bool

        origin:射线的起始点 direction:射线的方向。 distance:射线的长度  layerMask:只选定Layermask层内的碰撞器,其它层内碰撞器忽略。(注意仔细看截图,发现mask的值为Default,walls 意思就是说路径中只考虑Default,walls可能对路径的影响)*/

        

     



   

     
      if (Physics.Raycast(controler.transform.position, target.position, 1000F, mask))

     
            {

     
                    //Start a path from the unit(s) to the target position

     
                    if (units.Length > 0)

     
                    {

     
                        for (int i = 0; i < units.Length; i++)

     
                        {

     
                            //Call the seeker script to start a path to the target

     
                            units.StartPath(units.transform.position, target.position);

     
                        }

     
                    }

     
                    else

     
                    {

     
                    //从A——>BitStream进行移动

     
                        controler.StartPath(controler.transform.position, target.position);

     
                    }

     
             }

     
        }








欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5