2D Side Scroller AI: How Would You Do It?

I am working on a side scrolling game and currently I am developing the AI for the enemies. I am using a finite state machine to handle the AI, but I want to know what are some good ideas of how to make an NPC chase a player and be able to know where there are obstacles or pitfalls so it knows when to jump to avoid killing itself or getting stuck behind a rock.

I did some re-working to the PlatformController script that comes with the 2D Sidescroller Tutorial. I converted it to C#, added a class called Intention where I have variables that essentially emulate a controller and replaced all the areas in the code where it looks for a button press and instead looks at the variables in my Intention class. So I have the character following the player now, it just blindly walks off of edges and into immovable objects.

State Machine will only do as good as the info feeding it. You need to add triggers and pathing to keep it from jumping off ledges and when and how to jump and so forth.

Take jumping over a rock in the way,

If we want to move forward we hit a “rock” trigger, then get jump hight from rock if jumphight is < max jump hight then jump over wile moveing forward.

Falling off ledges,

If we want to move forward and we hit a ledge trigger then stop moveing forward and find something else to do.

This is where pathfinding usealy comes in. It gives the ai the info it needs about the world without having to do runtime (CPU costly) thinking, it just looks up the info it needs and acts on it.

If thats not enoth info there alot more and better then I can type here at : http://aigamedev.com/

EDIT: seems I didn’t read previous post… sorry. I guess my idea was the right one then :stuck_out_tongue:


How about making triggers all around your environment that will interact with your AIs… like telling them to jump over the said rock (if they have the ability to jump)?

Well I was hoping to get something so it can figure out how high it needs to jump based on the physics colliders or whatever so I didn’t have to manually place waypoints for pits and put navigation helper scripts on every object, but I guess it would take more time to figure out the dynamic AI logic than it would be for me to make triggers and waypoints. Thanks for the link too. I will look through it later today when I get a chance. Hopefully I can figure out some applicable tips in their non-premium articles.

To do this dynamicly, Google: ai_systems_of_l4d_mike_booth.pdf (I cant find my link to it)

And look at how they make the zombies climb walls and avoid stuff. It shows a good way to do this.

Thanks for the link, great info there.

Again, thanks for the link. It gave me some good ideas for how I should approach my problem :slight_smile: