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

I love this so much!
I’ve been hyping up brickccentric with this example so much lately, it’s truly amazing, and I’m super excited to use it.

Here are some screenshots from when I first tried it - To Hype you up:
Performance :ok_hand: :sparkles:


It goes through this part!
image

5 Likes

O my god this is insane!! Any angle pathfinding??? I wouldn’t even know how to start! Pls explain it a bit

5 Likes

Ok, do you know how breadth-first search works? This uses a breadth-first search but then the AI does line-of-sight checks while moving, to determine the waypoint that is closest to the target but that the AI can still see from its position.
Usually in a breadth-first search you would store some kind of direction value for each checked position that tells you the direction it was checked from, but this doesn’t store any direction values at all.
Instead, the order in which positions are checked tells you how close they are to the target—if a position is checked and found empty then it’s added to a list, and since each position is checked before expanding its neighbors, positions closer to the target will be closer to the start of the list than positions further from the target.
Then the AI simply searches the listed positions in order, and the first position it can see, it stops checking and aims for that one.

1 Like

yeah, I’ve done my own breadth search pathfinding before. So are you using raycasts to see if the AI can still see it from it’s position? How do you tell if it can see that position?

2 Likes

Yes, the AI’s send a raycast out to the position, with the ray set to check for wall objects. Since the ray only extends the distance between the AI and the specific position, a Miss output means there are no walls between the AI and the specific position (so the AI can see the position), and a Hit output means there is at least one wall between them (so the AI cannot see the position).

3 Likes

AHH! This is crazy!

I know right!

2 Likes

Just finished version 3 of my basic top-down pathfinding; here are some of its features:

-super fast performance (you could actually add this to a game and have it still be playable)
-multiple targets and followers
-moveable / destroyable obstacles, targets, and followers
-dynamic map boundaries (you can go out of bounds and the pathfinding still works)
-easier to edit code (though it’s still kind of complicated, so let me know if you have questions)

There is, however, one big downside to this version, which is that it uses the Message behavior instead of the Global behavior. This means you cannot just copy and paste the code like before— you have to make sure you set all of the messages up properly. I’m sorry it works that way; Messages are just so much faster than Globals performance-wise.

Also I am working on making this Any-Angle, but it’s ended up being more complicated than I initially thought, so it may take a while to actually complete it. Same goes for the platformer / sidescrolling version of this; it’s going to be a lot more complicated to implement (thanks to gravity).

9 Likes