4 Pathfinding / Player Follow Examples (Platforming & Top-Down)

If you’ve ever wanted to make NPC’s move intelligently around obstacles to a target, look for and follow a player character around, or just wander the map without getting stuck, then here are 4 example games that demonstrate exactly that:

There are 2 main ways here to set up the “pathfinding”, depending on how you want the NPC’s to work. The first one requires you to select a target for all the NPC’s to pathfind around walls to, and it assumes they know how to navigate the entire map. The second way is when there is a player, and the NPC’s wander the map until they see the player, and then they follow the player, based on where the player goes.
Also, since most games are either top-down or platforming / sidescrolling, I’ve made both versions of pathfinding in both types of games (hence the 4 games total).
Feel free to copy or improve on anything here!

9 Likes

They seem flawed. The ais never really track you unless they are right next to you in the first place. The top down one seems to not work at all.

3 Likes

They have to see you first (they have a 120 degree field of view).
If you’re behind them, they can’t see you, so you have to pass in front of them.

4 Likes

Did you give the player this color scheme on purpose?
image
Because this looks like Dream (:nauseated_face::face_vomiting:) being chased by his stans (also :nauseated_face::face_vomiting:).

2 Likes

pretty cool!
could you make once where the players can go in a tangent velocity instead of just the 4 cardinal directions?

2 Likes

No, the NPC’s are just yellow / tan because that’s the color the top down smiley ones were; I used green for the player because the targets were already red, and I wanted them to be colored differently…

2 Likes

Certainly; for which game? Or for all of them (because it would mean different things for each one)?

1 Like

This seems like a cool concept! I find it difficult to have enemies navigate around walls like that, so I’d be interested in seeing where this goes.

2 Likes


Understandable, have a great day.

1 Like

once the smilies notice you, they never stop chasing, even when your far out of sight

other than that this is really good

2 Likes

the top down one

1 Like

Which top down one, the one with a player or the target one?
I’m assuming the one with a target as the player one already has angular velocity.
If that’s the case, I think what you’re asking for is called Any-Angle pathfinding, and it’s a lot more complex then the simple Breadth-First Search employed here. Basically it would entail checking every single possible angle at every single point, and though there are optimizations, I don’t know that it’s possible at the moment in Flowlab (with reasonable performance anyway).

However if all you want is for the Characters to move with angular velocity and you don’t care about their path being all right angles, if you check the game now I’ve switched them to smoothly rotate between angles while they move; is this sort of what you mean?

2 Likes

Thanks for the feedback, and you’re exactly right, they never stop following you (unless they somehow reach a place the player hasn’t been in yet).
An NPC “forgetfulness” mechanic would be pretty simple to add, whether it’s to forget about the player after a certain time chasing them, or after a certain time not seeing them, or after they get a certain distance away, etc.
But I feel like this is something to be added on a per-game basis.

2 Likes

Ron from FNF
image
image

2 Likes

Bruh I don’t play fnf and never played any mods before but ok

1 Like

No, I meant the comparison.

2 Likes

I see now; you had or still have a different idea. I understand.

2 Likes