Knowing if player is unreachable - clarification

  • A* version: [5.4.7]
  • Unity version: [6000.0.84f1]

This is a bit of a follow up from the post: “Know if the player is Unreachable?”. (Tried to link it but not allowed yet!)

admin edit:

I have currently been struggling with this problem for quite a while, where the agent will simply go to the closest node it can traverse until getting stuck there. While I have managed to implement the solution from the previous post myself, it leads to very janky movement when the player is unreachable because it needs to consistently figure out if the player is reachable again by attempting to find it again, leading to jittery movement as it twists and turns managing the new path. I have remedied this somewhat by changing UpdateRotation and UpdatePosition but this leads to other types of jitter and also risks breaking the visuals in other instances if done carelessly, because of custom animations on link traversal etc.

My ideal solution is something like this:

Calculate path to player using Agent constraints (do not give to agent) → Check if path to player is complete

If Path is complete → Give path to Agent

Else → Give a different target

I’ve been trying versions of the solution in the previous post but ABPath calculations seem to always return nodes at the players position.

Other solutions I tried were things like using NNInfo Constraints to find walkable nodes and calculating distances to see if the player was reachable but this didn’t work.

I’m sorry if I am missing an obvious solution, been trying my best at working with the Tutorials and Documentation before posting. Been loving this package and had no issues working with it up until now!
Thanks in advance!

Added the link to your post!

So yeah I was gonna say you’re on the right train of thought with Nearest Node Constraints. Are you able to post some of your code that you’ve tried and we can see what’s going on?

Okay so funny story: I could not find the code itself in my repo history so I went and rewrote it, only to have it work as intended! I haven’t tested the full solution with an ABPath Calculation but from here on out I feel very sure about that it’ll work.

 NearestNodeConstraint constraint = NearestNodeConstraint.Walkable;
 NNInfo NodeInfo = AstarPath.active.GetNearest(playerPosition, constraint);

 //TODO: USe ABPath to check if path is valid, add into pathComplete

 bool pathComplete = (Vector3.Distance((Vector3)NodeInfo.node.position, playerPosition) < 1);

Thank you for pointing me in the right direction!

I think why this didn’t work before was because nodes outside the intended area were set as walkable:

image

(This was not ticked)

Now the agent wont go to the player unless it knows it can!