How do I make a platformer pathfinding?

0 favourites
  • 2 posts
From the Asset Store
10 Retro songs ideal for platformers or farming games
  • I just want an ai that is able to chase the player until the player is either unreachable or dead anywhere in a 2d platformer environment, someone gave me a template on discord but it only takes the shortest path using the pathfinding behavior and walks and jumps towards the nodes instead of calculating the proper path, which i know is going to be hard

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hey. I'm new to Construct, so keep that in mind when reading this. However I've tried implementing 2D platformer pathfinding numerous times in the past, with various levels of success via low-level code and/or engines like Unity.

    Long story short.. This is tremendously more difficult than simple topdown pathfinding.

    There are two reasons for this:

    a) One is that there's no one "path node" concept in 2D platforming.

    Usually you'll have to break down your platforms into specific chunks. If the entire area is traversable by walking without any jumping/falling (or heaven forbid any other move mechanics), then that's a single chunk. I call that chunk "ground" or "segment" but there's no common name for it. Then you need to keep track of each agents/enemies current node, as in which ground they are on right now. You can set this by their last landed node.

    You could say this segment is itself a "pathnode" except it's not that simple. You need to precalculate all the ways in which you can move from a ground to another ground. And this means you need several sub nodes within your ground node. This includes the segment's two line vertices (the farthest left-right nodes, from which you can fall to other grounds) as well as certain convenient position nodes in the middle, from which you can jump (or whatever) to another ground.

    So for example, if you can jump from ground A to ground B then you have to position a node in ground A just right so that an agent can walk to it first before attempting to jump to ground B. Otherwise the jump will fail. You also have to save the state within that jumpnode, the accurate direction and force to jump. And sometimes you can fall from a segment to another segment but you can't jump back to it because it's too high.

    You either have to place those nodes manually per each level (huge work, prone to mistakes) or dynamically place them at runtime via some jump/fall conditions. For example, place a jump node if there's a jumpable platform etc (ideal solution but really harder than it seems.)

    b) This still does not account for the randomness of physics to begin with.

    2D platforming uses a physics engine. This means that you really don't know what's going to happen. If you use fixed update (so that the physics is always the same as long as the input jump direction and force is the same) then you can reasonably expect that the physics tick always help your jump from a ground to another ground to have stable outcomes. So check first if Construct ticks occur in fixed time and don't have random variances.

    Second... EVEN IF you manage to precalculate a stable jump/fall that will always occur the same way... there's always something happening in a fast paced 2d game. Like your enemy can be hit by a bullet, it can miss a collision or two, etc etc. You don't know what's going to happen. So trying to make pathfinding and physics work at the same time is a pretty difficult thing to do. There's only a handful of games that made this happen (check out RainWorld if you're interested. To my knowledge they're the only ones who truly used pathfinding to their advantage in a 2d platformer stage.)

    Yes I know fast-paced 3d games have pathfinding. But the reason it works in 3d space is because navmeshes are time-tested and possibly the only way to adequately move AI. And if you think about it, a navmesh is all just 1 ground segment - as in, you can traverse most places via walking. It's very hard to set up even navmeshes for moving platforms and broken up platforms - as in many ground segments that you have to jump/fall to or use other gimmicks to move to... instead of one. There's plenty of that in a 2d platformer, making it extremely harder to implement.

    So what I'm tryint to say is...

    This is not something you can reasonably expect from Construct let alone any engine. Even big titles like Unity or Unreal cannot even attempt to provide this. I honestly think it didn't even occur to them.

    If you want to script this yourself in 2d platformer space... good luck! You need a lot of it. All I can say is I tried. What I suggest is to really really really reconsider if you absolutely need/want this for your game. If you do, I suggest something more.. uh.. low level.. learn pathfinding algorithms like astar to the best of your abilities... and/or work very closely with the faculties of Construct.

    Sometimes, for most cases, just making the enemy follow your horizontal directional (and jump when they hit a wall) is enough.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)