AI question: CPU going to the player's nearest node

Hello! As usual, I am as noob as that I don’t even know if I can just ask what I am about to ask! :open_mouth:

I am thinking of a ““3D game”” that is basically a simple map/maze where two characters (Player and CPU) can move from a “node” to another. Now the AI should make CPU seek player through those nodes. In your opinion how do you accomplish this task?

CPU should use the shortest way to reach last known node the player was (or next node player will be), but as a dumb and a noob, how can I calculate the shortest path from actual cpu node to last (or next) player node?

Thanks and sorry for my english!

You might want to start researching A* pathfinding or Unity NavMesh and NavMeshAgents.

Here is a resource I used to create my own A* implementation. Mind you have to fill in the gaps but it teaches the concept well.

Depending on your skill level it may take a few days of tinkering.

Link: Making smarter monsters: Adding pathfinding to Unity’s 2D Roguelike tutorial | by Jimmy | Medium

Thanks so much! I will look for A* and NavMesh! :slight_smile:

If you do go down the route of A*, try to limit the number of ‘for’ or ‘while’ loops you are doing, because as you scale up you’ll get performance problems. That’s what I figured out anyway. Just be as efficient as possible with how you fit it together and you’ll be fine.