Saturday, July 29, 2017

path finding - How can I implement platformer pathfinding?


I've gone through A* pathfinding but could find anything on this. What I'm looking for is pathfinding for something kind of like a super smash bros level with different platforms. Can anyone point me in the right direction?



Answer



This entirely depends on the nature of the game's platforms. Can you jump through them from below? Can you drop down through them while standing? Can you pass through them while falling without landing? Can an NPC jump/glide/accelerate in a specific direction mid-air?


These are all questions you should be asking when implementing your pathfinding algorithm.


All in all, A* is pretty much applicable to all pathfinding. It's a very, very abstract algorithm, and all it requires is some sort of system of points or nodes in one form or another (polygonal vertices/edges/faces all work great for representing these) with some way to determine the "cost" of moving from one node to the next.


Given that the platforms will likely be flat surfaces, with no third dimension of movement, you could easily use a system of points that define the borders of each platform (left and right), and treat everything between those points as "walkable." From there, you just need to get your NPC to the goal location (which is decided by the AI behavior more than the pathfinding algorithm).



If you want to define AI behavior to be, say, "melee" aggressive, you'll likely want them to get as close to the player (or enemy, if the NPC is friendly) as possible, so they can attack them.


If you want to define AI behavior to be "ranged," you will likely want to find a position where the NPC is "safe" (distanced) but has a clear shot at the target.


The most efficient way for an NPC to detect these sorts of "hot spots" for target finding would be to pre-program them into the node map, itself.


For example, many NPCs in modern games know how to take cover behind obstacles, in combat. This is generally not because the AI is taught how to detect if an obstacle has a large enough bounding box to be used as cover, but rather because there is a pre-defined node (or, in fancier implementations, a polygon covering an area that is "acceptable to take cover at") told them that they should go there, and they likely detected that the player had too clear a shot at them (either by raycasting to the player's line of sight, or by the player's relative position with respect to the current position of the NPC).


AI behavior is full of quick little hacks like this that can all combine to make a fully functional, believable NPC.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...