Stop before reaching destination (AILerp on grid based game)

I have an object that needs to chase a target when it is in view. For the most part it works simply by setting ai.destination to the target. My game is played in real time where the different entities walk in 4 directions on a grid (which is why I’m using ailerp). Both the target and the “chaser” will be moving around constantly. However I can’t figure out a way to stop them when they are adjacent to the target (1 square away).

I have tried setting the position of the object to itself when it is nearby. The problem with this is that the chaser will sometimes go on top the target then walk back out.

I have tried to figure out a way to get access to the waypoints and just set the destination to the waypoint before reaching the target:

    void Update() {
        
        if (Time.time > lastRepath + 0.5f && seeker.IsDone()) {
            lastRepath = Time.time;
            seeker.StartPath(transform.root.transform.position, fov.visibleTargets[0].transform.position, onPathComplete);       
        }
    }

    void onPathComplete(Path p) {
        ai.destination = p.vectorPath[p.vectorPath.Count - 2];
        ai.SearchPath();
    }

Which kind of works, but this results in shaky movement when the chaser will stutter for a bit before reaching the target. Also it will not move again after reaching the destination.

I’m just confused as to what to do. Just setting ai.destination gives me perfect movement, but I just can’t stop my object before reaching the destination. I do not have the paid version of this package btw.

1 Like