RichAI failing to reach destination in on flat terrain with no obstructions,

Hi,

I feel like I’ve visited this one before but I can’t seem to find the answer in the forums. Essentially for any given nav that i want the AI to do i need to know whether they get to the destination or not. The helper functions i have that determine this (which previously seemed to work) look like the following:

	public bool HasFinishedNavigatingHitTarget()
	{
		NNConstraint constraint = new NNConstraint();
		constraint.graphMask = 1;

		GraphNode current = AstarPath.active.GetNearest(GetNavMeshAgent().position, constraint).node;
		GraphNode destination = AstarPath.active.GetNearest(GetNavigationTarget(), constraint).node;

		return PathUtilities.IsPathPossible(current, destination) && GetNavMeshAgent().reachedEndOfPath;// && GetNavMeshAgent().reachedDestination;
	}

	public bool HasFinishedNavigatingMissedTarget()
	{
		NNConstraint constraint = new NNConstraint();
		constraint.graphMask = 1;

		GraphNode current = AstarPath.active.GetNearest(GetNavMeshAgent().position, constraint).node;
		GraphNode destination = AstarPath.active.GetNearest(GetNavigationTarget(), constraint).node;

		return !PathUtilities.IsPathPossible(current, destination) && GetNavMeshAgent().reachedEndOfPath;// && !GetNavMeshAgent().reachedDestination && !GetNavMeshAgent().pathPending;
	}

Can we start from first principles please, ignoring the code above? I would simply like to know how I’m supposed to determine when an AI succeeds or fails to navigate to where I tell it to. I’m currently testing on a big open plane terrain with a recast graph and with no obstacles in the way and the target destination always on the nav mesh and it’s sometimes failing.

Thanks,

It looks like i also posted here Unable to reach destination.

heh.

Ok so i can repro it with the helpers looking like:

https://forum.arongranberg.com/uploads/default/original/2X/5/569b8735b0e5564e3d6263f744b128845a5eb0ea.png

Hi

Do you want to know, before the agent starts moving, if it can reach the destination. Or do you want to see if the agent has currently reached the destination? I couldn’t figure out which of the two you are interested in. :slight_smile:

Hi,

The game is quite fluid. It’s golf so the golfer hits the ball and it may roll somewhere (while they’re naving to it) like under a tree where they can’t get at it. I need a reliable way of doing that they tried to get to it but couldn’t. I need them to make a decent go of getting to it as well.

Thanks,

Just some further clarification - with the above scenario of a RichAI walking on a nav mesh with no obstacles to the destination point the below evaluates to false sporadically:

reachedEndOfPath is true, reachedDestination is false and pathPending is false. There appears to be a blip where the player has neither got their or has a path pending.

I’ve logged the frame indices that this returns true and it’s very infrequent.

I’ve also seen occurances where reachedEndOfPath and reachedDestination are true but pathPending is also true.

Thanks,

Sorry for the spam, i just want to give as much context as possible.

This is a pic of whats happening:

These are the relevant values for the RichAI:

Thanks,

Hi

If you want them to

  1. Navigate to the closest point they can reach
  2. At that point, check if they actually reached the ball.

Then I would do something like this:

// When you want the agent to move to the ball, do
ai.destination = ball.position;
ai.SearchPath();
// Every frame check
if (ai.reachedEndOfPath && !ai.pathPending) {
     // Or some other threshold
     if (ai.remainingDistance > ai.radius) {
          Debug.Log("Failed to reached the ball");
     } else {
          Debug.Log("Successfully reached the ball");
     }
}

Thanks,

With this solution i have pathPending set to true when in this sitatuation:

image

The player is below the target because the height difference between the nav mesh and the terrain is quite large.

Thanks