Help on how to make a simple waypoint system for AI?

Okay so I was wondering if someone could give me advice on how to make a simple waypoint system that my AI can follow. The way it would have to work is there is a series of objects that are around my map that the AI has access to. Depending on which waypoint I am closest too the AI can pick the fastest path to the way point which ultimately leads to me. I do not want any plugins specifically because I would like to make it specifically for my game, I want to code it myself I’m just not sure where to begin. I drew a few concept pictures.
Thanks!

right click, open in new tab to see the pictures better.

Example 1:

Example 2:

For each waypoint you could have a list of all the other waypoints you can get to from there and an associated cost value. With this information you can run an A* search to find the shortest path between any two waypoints.

You could generate the list of connected waypoints on level startup by raycasting to all the other waypoints to see if there are no obstructions in the way. The cost value could simply be the distance to the connected waypoint.

The A* algorithm isn’t too tricky to code. There is pseudocode on wikipedia:

thanks for the reply, seems a bit complicated but i’ll look into it more. Anyone else have any ideas?

Thanks.

Gibbonator is right. I think it’s the best solution. Also you can just sort list of points in each vertex.

Where to begin would be pathfinding. You will need this, no matter what. I wrote an A* solution for my game by translating the pseudo-code from Wikipedia and it works great. Get your AI working such that they are able to path from their current location to any arbitrary point.

Once you can do this, then you can start making design choices like when to chase the player, and what to do when you’re not chasing the player.

Is there a reason that you don’t want to use Unity’s built-in navmesh functionality? It would be pretty simple to build the waypoint system that you described on top of that.

As most standard approaches have already been mentioned, I’d suggest, in case you don’t want to code your whole pathfinding solution, to take a look at aaron granbergs A* asset. To be entirely honest, I think it’s a pretty solid and complete solution for any type of pathfinding you could possibly imagine in a standard game.

Then again, it’s the asset store, but it’s cheaper than unity pro and it’s navigation system, and it’s way better. Maybe even use it’s free limited version, to have a glance at how it works.

In response to nulldiver,

If that question was for me, then my reason is that my game is a top-down 2D grid-based game and using a navmesh on that would be insane overkill. And since this is the only Unity game I have worked on in the last year-and-a-half, I didn’t even realize Unity had a built-in navmesh functionality. :slight_smile:

Oh and also it looks like it is a Pro-only feature.