示例#1
0
 public void actuallyRePath(Vector3 place)
 {
     if (MovementAI.lastRepathTime - Time.time < 0.10)
     {
         ai.fpscounter = 0;
         path          = ai.getPath(gameObject.transform.position, place);
         path.pop();
         ai.currentNode = path.pop();
         halfwayPoint   = path.length() / 2;
     }
 }
示例#2
0
    public void PathFindTowards(Vector3 place)
    {
        if ((halfwayPoint < 5 && ai.fpscounter > ai.fpsreset) || (halfwayPoint >= 5 && path.length() < halfwayPoint))
        {
            actuallyRePath(place);
        }

        if (Vector3.SqrMagnitude(this.transform.position - target) < 0.01)        //Move on to next node
        {
            this.rigidbody2D.velocity = new Vector2(0, 0);
            ai.currentNode            = path.pop();
        }

        if (ai.currentNode != null)       // Move to current target node
        {
            target = new Vector3(ai.currentNode.loc.x, ai.currentNode.loc.y, 0);
            this.setDirection(target - this.transform.position);
            Move();
        }
    }