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!

15 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.

5 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

The recent help request reminded me that I have actually made a better / more optimized version of my top-down pathfinding:

The difference isn’t very noticeable just playing it, but the code is much better organized and streamlined, so it runs much better overall.

6 Likes

Wow, this is insane. The best pathfinder I’ve every seen, lol.

2 Likes

1st Game: A little while ago, I created this top-down pathfinding system that does NOT use ANY waypoints or ANY extra spawned objects (all the pathfinding is calculated in the brain and any target objects). It does require a bit of extra code in the walls and a separate parent object for . . . everything (i.e. the AI, Walls, and Target are all parented to 1 object).
2nd Game: Then I had an idea for how to turn the pathfinding into ANY-ANGLE pathfinding, meaning the AI’s find the shortest path to the target at any angle at all, not just multiples of 90 degrees.
I have not finished refining these games yet, but I figured (since I’m not actively working on these right this moment) that I might as well share what I’ve got so far. So the performance and code in general are not yet as optimized as they could be, but the basic system is in place and works. (Ironically, the any-angle pathfinding is more optimized than the regular breadth-first search version.) I am going to work on these more in the future.
For now, feel free to take the code and run with it. If you’re interested in how something works, just ask, though I can’t guarantee I’ll have time to give a full, in-depth explanation.

9 Likes