2D AI (platformer) creation help?

Hi! I’ve gotten to the point in my game where I have to start worrying about AI creation… The thing is, I’m not very familiar with AI. I barely dealt with AI back when I started working with games, and it was very simple and trivial. The game that I’m currently working on is a 2D sidescrolling platformer, very similar to “Samurai Gunn”. The AI that I’d like to come up with has to “know” how to do the following things:

  1. If the player is within range, begin following him. If he’s within a certain range, either sprint or walk
  2. Be able to jump over obstacles (probably a line trace and then checks for a tag)
  3. Be able to figure out how to walljump to the player’s location
  4. When the player is within a certain range, attack him
  5. Sometimes jump randomly over the player (he can attack in air, makes the AI feel better)
  6. Sometimes throw a weapon
  7. Sometimes block the player’s attacks

The player can already do all of those, I just don’t know how to get the AI to do all these. I’m really confused were this is concerned, I need someone to help steer me in the right direction please XD (I’ll buy you a beer :'3). From that list, I can somewhat grasp my head around how I would do most of these (except for 3, I have no idea how to do that one O.o), but I don’t really know what I would use. Would I use behavior trees? AI controllers? How would I use these in a 2D game? Anything helps, really. How would you do any of these?

Thank you so much!

I have done a few of these actions. I don’t know if this is the right way but this is how I figured it out.
Most of that is going to be trigger boxes and booleans.
Once the player overlaps the enemy’s trigger box then set what you want to happen.
So my first trigger would be bigger so as soon as you hit it the enemy starts moving towards you, then have another trigger box thats closer to the enemy but can only overlap the player pawn otherwise it will bug out. Set that one to have the enemy attack if you enter it.
The way I got the enemy to move towards me was an event tick and subtract the players location from the enemys location and use set actor location. It will constantly be pushing the character towards you. You will prolly have to lock it on a certain axis though.
As for jumping I just got a check on the enemy’s velocity and if they got to where they weren’t moving on the X then I would have them jump, so basically once they run into something they slow down then it jumps.
You could have the enemy jump on a trigger collision from the character.
You would have to set up a random system so that when the enemy triggers the collision it has a chance to jump, if thats how you’d want to do it.
You could also use the random system for all your “Sometimes”
What I mean by random system, and this is just how I do it, I have on event trigger pick a random number between ??–?? whatever you want to set it to, and set that number as a random variable, then do a sequence, if that number is equal to 1 this happens, if equal to 2 this happens, etc…
As for Wall jumping, that is beyond my abliity, but you may be able to figure it out once you do this other stuff. :smiley:

Hi there! Thanks for the reply, I appreciate it :slight_smile: I basically did those things like you said, and it seems to work pretty well. The issue I’m facing now though is that since the triggers only fire once, I can’t have it detect when the player is above the enemy… Do you get what I mean? I recently posted another question about box traces, if you could help me there I’d really appreciate it!

Either way, thank you!

You could make a trigger box that includes only the Player and the space above him where you want that ‘be above him event’ to happen.