The Daily Click ::. Forums ::. Klik Coding Help ::. Beat'em-Up A.I
 

Post Reply  Post Oekaki 
 

Posted By Message

Benny Lindberg



Registered
  08/11/2010
Points
  54
9th November, 2010 at 22:48:38 -

Hi there! I'm currently working on my first longer game, a beat'em up in the style of TMNT and so on.

The problem I'm having is with the enemy A.I. As it is now, I've gotten them to home in on my character and hit when near. This leads to you getting swarmed of course,
so I'd like to make them "hesitate" and so on, as seen in most sidescroller beat em ups. Any ideas on how to accomplish this? I haven't found any tutorials describing the behavior I'm looking for. There was a beat'em up tutorial featuring Amy, but the A.I didn't behave as I wanted.

Grateful for any answers!

 
n/a

HorrendousGames

Sourpuss

Registered
  31/10/2009
Points
  481

VIP MemberEvil klikerGame Of The Week Winner
10th November, 2010 at 07:14:17 -

I'll take a stab at this.

AI can get pretty messy if you don't plan ahead first. And in order to get hesitation just right, you'll need to use a few timers, randomizers and of course states.

I'm not sure on what you're using for your attacks and whatnot, but lets say the AI has a few tricks up their sleaves like punch, kick, dodge and run. Also, the AI will of course have to notice the player, and all that jazz.

So get yourself an alterable string, and lets call it "State". This will be a text representation of what the AI is doing. Initially, it should be in a state called normal, and of course all your normal actions should be here (just make a condition on all the "normal" action codes that says State = "normal") Then of course when the AI notices the player, change the state to something like "chase". during this state, the enemy will move up to the player.

Now you should make a few commands for chase (such as pathfinding, depending on how complicated your levels are, but of course for a TMNT style game, I'm sure it's all pretty open areas), but it needs a code to get out of chase, and one to progress further. Say something like if distance to the player is greater than x amount of pixels, change state to "normal". (use the pathagorean theorm to determine distance in a separate value, something like always change "distance" of enemy to PT between player and enemy, [I forget the actual equation because I'm lazy and I use an extention]) Then of course, when the distance of the player is lower than x amount of pixels, then change the enemy state to "attacking". At this point, in that very same code, set a value on the enemy, we'll call it "attackCountdown" (initialize it to -1) to something like 50+random(50). Keep this value kind of small for the first attack, and naturally put an event that says when countdown is greater than 0, subtract 1 from countdown.

Now, once that value is equal to zero, you are going to randomize another counter, call it "attackChoice"(initialize to -1), and you are going to have to do a bit of planning on this one. Obviously you're going to want enemies to do certain decisions more than ever. So lets say when countdown is equal to zero, then randomize attackChoice to something like 10, then set countdown to -1. Then you'll have to set up different events to tackle each choice.

With punch you'll start off the choice something like if attack choice is equal or greater than zero but less than 4, then punch, set choice to equal -1 and countdown to something like 250+random(100). The kick is the same thing except the trigger will be if choice is greater than or equal to 4 but less than 6. And of course the dodge and run, same thing, just change the conditions for the choice number.

The final thing to consider is if the player runs away when the enemy is attacking. Do the same thing as getting away from the chase, which is if the player's distance is greater than a certan number, either change the state to "chase" or "normal".

I typed this up pretty quick so if I forgot something, or I explained it in a confusing manor, let me know and I'll help you further.

 
/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/-=?=-/
That Really Hot Chick
now on the Xbox Live Marketplace!

http://marketplace.xbox.com/en-US/Product/That-Really-Hot-Chick/66acd000-77fe-1000-9115-d80258550942

http://www.create-games.com/project.asp?view=main&id=2160

Benny Lindberg



Registered
  08/11/2010
Points
  54
10th November, 2010 at 13:39:59 -

Thanks! I'm gonna try it out

 
n/a
   

Post Reply



 



Advertisement

Worth A Click