2d Plattofrmer. Enemy AI finding paths.

For a 2d plattformer i am thinking about enemy AI. When an enemy needs to get to a higher plattform i need it to be able to calculate when and where to jump, or if it will be able to make the jump. How would i go about doing that?

Im thinking, there will be ladders and there will be other platforms in falling or jumping distance. The enemy is just supposed to get to the players position. So something like this

  • Check if target is on the same y level. move horizontaly.
  • Check if there are any obstacles (check for colleiders) between self and player.
  • If obstacles in path, check height if it can be jumped on top of. If not check if there is a ladder.
  • If target is above check if targets platform has a ladder leading down to same level as self.
  • And so on.

I totally have no experience of this so im shooting in the dark. Curious about more experienced people experineces.

Most platform games simply avoid this and only have enemies following simple rules. If you’ve never done this kind of thing before perhaps explore simpler options like patrolling back and forth unless you have very specific needs to have agents be fully aware of the world and how to navigate it.

This might get you started with some ideas:
http://www.ludumdare.com/compo/2013/11/24/path-planning-ai-in-platformer-games-a-layered-approach/

You will want to build some sort of reach-ability graph of the level and then use an algorithm like A* to find the lowest cost path through it.

From 30 seconds or so:

Personally I find the best approach to AI is just hacking at it until it works. Once you get something that works, then you go back and refine it (i.e. rewrite with all the superfluous stuff removed :slight_smile: ).

In this case this AI just has a few parameters that let it know how far it can jump, then it simply tries to go higher if the player is above, or towards the player if player is same height/below. Despite these simple rules it looks somewhat like the AI is planning :slight_smile:

Interesting. Can you share any code?