Exemplo n.º 1
0
 void GoToNextNode()
 {
     previousNode = currentNode;
     currentNode = currentNode.Nearest(target.transform.position, previousNode);
     if (currentNode) {
         SetDestination(currentNode.transform.position);
     } else {
         Idle();
     }
 }
Exemplo n.º 2
0
 public NavNodeScript Nearest(Vector3 position, NavNodeScript exclude)
 {
     NavNodeScript closest = null;
     float distance = Mathf.Infinity;
     foreach (NavNodeScript node in neighbors) {
         if (node != exclude) {
             Vector2 diff = (Vector2)node.transform.position - (Vector2)position;
             float dist = diff.sqrMagnitude;
             if (distance > dist) {
                 distance = dist;
                 closest = node;
             }
         }
     }
     return closest;
 }
Exemplo n.º 3
0
    private void getNextNode()
    {
        NavNodeScript     currentNavNode = currentEnemyNode.GetComponent <NavNodeScript>();
        List <GameObject> neighbors      = currentNavNode.neighborNodes;

        neighbors.Add(currentNavNode.gameObject);
        int   closestNodeIndex    = 0;
        float closestNodeDistance = 1000.0f;
        float distanceToNode      = 0.0f;

        for (int i = 0; i < neighbors.Count; i++)
        {
            distanceToNode = Vector2.Distance(neighbors[i].transform.position, currentPlayerNode.transform.position);

            if (distanceToNode < closestNodeDistance)
            {
                closestNodeDistance = distanceToNode;
                closestNodeIndex    = i;
            }
        }

        targetNode = neighbors[closestNodeIndex];
    }
Exemplo n.º 4
0
    void SearchStart(bool to)
    {
        if (!target) {
            Idle ();
            return ;
        }
        state = State.MOVE;
        timeout = searchTimeout;
        willTimeout = to;
        GetComponentInChildren<Animator> ().SetTrigger ("walk");

        currentNode = navGraph.Nearest(transform.position);
        previousNode = null;
    }