playMaker

Author Topic: Best approach for 2D AI  (Read 8663 times)

Mayhem

  • Full Member
  • ***
  • Posts: 171
Best approach for 2D AI
« on: July 11, 2013, 12:33:01 PM »
Hey there.

The last weeks I was working on the AI for my 2D Platformer game. I watched the Tutorial-Series on AI with PlayMaker and tested some things and got it working. The Movement was done by iTween when patrolling or chasing the Player. But I ran into some problems on the platforms -> when the Player jumps from the platform where the enemy is located and is chasing the Player to another platform the Enemy is of course chasing the Player and falls into the pit. I tried making two Boxes which where Triggers and served as Waypoints  but couldn't manage to achieve a rocksolid AI which stays on the platform.
Some of the Enemies should chase the Player, if they reach an end of a plattform, they should stop. (While Patrolling, Chasing and Attacking the
Enemies are playing 2D Toolkit Animations)
Other Enemies can chase the Player over obstacles, meaning: they can jump over pits, too.

So, know I would like to hear some experiences on tackling this monster, especially with PlayMaker.
Do I have to bear in mind something special?
Should I try a Pathfinding-Solution like A* Pathfinding or Simply A* Pathfinding (http://forum.unity3d.com/threads/164003-Released-BFGames-Simply-A*-Pathfinding!) ?

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: Best approach for 2D AI
« Reply #1 on: July 17, 2013, 01:59:21 PM »
No suggestions on this :/ ?

guisquil

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Best approach for 2D AI
« Reply #2 on: July 17, 2013, 02:46:15 PM »
No solutions from me, but have you seen this? 

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Best approach for 2D AI
« Reply #3 on: July 17, 2013, 05:27:39 PM »
Some general advice:

Build as much of the "smarts" into the level as possible.
Use Triggers to control behaviors. E.g., jump triggers, stop triggers, turnaround triggers. Basically when the AI enters this trigger it's told what to do by the level.
Use invisible Collisions if there are areas AIs absolutely should not be allowed to enter.

Only if you need to, you can get more complicated:
Parent "sensor" or "feeler" triggers to AIs to make decisions. E.g., is there a drop ahead, is the ceiling too low to jump etc. Remember to mark these triggers as Kinematic since they are moved by the AI.

Beyond triggers, try to define the smallest set of states required by the AI. E.g., Idle and Attack. Only add more states as you need them.
The player needs to understand the behavior of the AI to play the game, essentially reverse engineering the FSM in their heads as they play. So keep it simple but fun.

In general, always try the simplest solution that might work first!
« Last Edit: July 17, 2013, 05:36:10 PM by Alex Chouls »

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Best approach for 2D AI
« Reply #4 on: July 17, 2013, 06:37:45 PM »
I'm going to toss my hat in here with the "Keep it simple" approach.

sure, you can work towards making a self-contained AI system that can handle anything you can throw at it but consider that each step you make it take is going to be a draw on the CPU and if you have an AI that's built for something that it's never going to encounter in the level that it's placed in, it's kinda going a bit into the "overkill" category.

That said, the triggers are also what i'd suggest... maybe a couple raycasts downwards at an angle to give it a "is this a ledge" detection and such as well as a "am i near a wall" kinda thing. Though, raycasts can become quite expensive in terms of CPU power usage and for some behaviors, a trigger/collider is actually more efficient.