Ejemplo n.º 1
0
        private QTNode FindNearest(QTNode root, Vector3 pos)
        {
            QTNode node = root.GetChild(0);

            if (node == null || root.lodLevel == this.lodLevel)
            {
                return(root);
            }
            float dis;
            float disTemp;

            dis = MathExtra.FastDis(node.center, pos);

            disTemp = MathExtra.FastDis(root.GetChild(1).center, pos);
            if (disTemp < dis)
            {
                dis  = disTemp;
                node = root.GetChild(1);
            }
            disTemp = MathExtra.FastDis(root.GetChild(2).center, pos);
            if (disTemp < dis)
            {
                dis  = disTemp;
                node = root.GetChild(2);
            }
            disTemp = MathExtra.FastDis(root.GetChild(3).center, pos);
            if (disTemp < dis)
            {
                dis  = disTemp;
                node = root.GetChild(3);
            }
            return(FindNearest(node, pos));
        }
Ejemplo n.º 2
0
 // Update is called once per frame
 public void Update()
 {
     if (MathExtra.FastDis(playerTrans.position, oldPos) >= 1f)
     {
         Execute();
         oldPos = playerPos;
     }
 }