Accessing random point on grid graph

  • A* version: [4.2.17]
  • Unity version: [6000.3.10f1]

I want an enemy in a certain state to select a valid point on the grid graph from a given radius. How could I access the grid graph to retrieve a location? And if someone knows implementation to randomize a location from a radius that would be even more helpful.

You can use a NearestNodeConstraint for this. In more detail, you can use NavGraph.RandomPointOnSurface and feed it a NearestNodeConstraint when your enemy is in that specific state. NearestNodeConstraint has a variable, NearestNodeConstraint.maxDistance for exactly this. And if you want more complicated logic (ie, I only want them to go to points that are in front of them by way of Vector3.Dot) you can use NearestNodeConstraint.filter.

Thank you for reply. If you understand A* well may I also ask what tips you have for using the Destination Setter component for a top-down 2D game?

This tutorial has a few approaches that you can use: Wandering AI Tutorial - A* Pathfinding Project

1 Like

I can’t think of many tips for this component really, as it’s pretty straightforward. But if you’re looking for particular destination-changing situations you can let me know what you’re trying to accomplish and I can try and help.