Update actual and destination node on a dungeon crawler

Hi,

I work on a dungeon crawler like Eyes of the beholder or Legend of Grimrock more recently.
So I used your free project on a grid graph with 4 connections, no Collision testing, no Height testing and for the target activate the ClosestOnNode option.

What my sript does is :
Calculate the path to the aim
Put the next node location into a variable
Make available my actual node (An other prefab can use it now)
Disable the destination node (Like that no other prefab can go there)
Move to the destination node

When I use my code on one target it is perfect, once it reaches the waypoint it comes back to the initial position, the nodes are updated exactly how it should.

The problem is when I put this code on multiple target, they become crazy and use diagonals, jump to 2 nodes straight, do not go to where they are supposed to, I do not know why.

When you have time could you have a look on this code?

If I disable the node part everything is Ok, I must do something wrong in this part.

Thanks, Cizia

`
using UnityEngine;
using System.Collections;

// Note this line, if it is left out, the script won’t know that the class ‘Path’ exists and it will throw compiler errors
// This line should always be present at the top of scripts which use pathfinding
using Pathfinding;

public class AIEnnemies_Light : MonoBehaviour {

public Vector3 waypointPosition;

// The calculated path
private Path path = null;

// Private
private bool busy = false;  

private Vector3 startPosition;
private Vector3 patrolDestination;
private Vector3 positionNodeArrivee;

private Seeker seeker;

void Start () {
    seeker = GetComponent<Seeker>();
    startPosition = transform.position;
    patrolDestination = waypointPosition;
}

void FixedUpdate () {

    // If busy, go out
    if (busy)
    {
        return;
    }

    // If we reach the start or the waypoint position, change the destination
    if ((transform.position - startPosition).sqrMagnitude < 0.5)
    {
        patrolDestination = waypointPosition;
    }
    if ((transform.position - waypointPosition).sqrMagnitude < 0.5)
    {
        patrolDestination = startPosition;
    }

    // Calculate the path to the destination
    seeker.StartPath(transform.position, patrolDestination, Path2WaypointCalcule);

    // Be busy until the move is done
    busy = true;
}

// We have the path, update the next node position, the actual and destination node avaibality and move to the next node
void Path2WaypointCalcule(Path p)
{
    path = p;

    UpdateNodes();

    iTween.MoveTo(gameObject, iTween.Hash("position", positionNodeArrivee, "time", 1, "easetype", "easeInOutQuad", "oncomplete", "ActionFini"));
}

// The move is done, no more busy
void ActionFini () {
    busy = false;
}

// Enable the start node, disable the destination node and update the var positionNodeArrivee
void UpdateNodes (){

    // Initialize positionNodeArrivee which is the next node to the destination
    positionNodeArrivee = path.vectorPath[1];

    // Do not change the height
    positionNodeArrivee.y = transform.position.y;

    // Create bounds
    Bounds boundsDepart = new Bounds(transform.position, new Vector3(1, 4, 1));
    Bounds boundsCible = new Bounds(positionNodeArrivee, new Vector3(1, 4, 1));

    GraphUpdateObject guoDepart = new GraphUpdateObject(boundsDepart);
    GraphUpdateObject guoCible = new GraphUpdateObject(boundsCible);

    // Define if walkable or not
    guoDepart.modifyWalkability = true;
    guoDepart.setWalkability = true;

    guoCible.modifyWalkability = true;
    guoCible.setWalkability = false;

    // Update the grid
    AstarPath.active.UpdateGraphs(guoDepart);
    AstarPath.active.UpdateGraphs(guoCible);
}

}
`

Up :wink: