Sign in to follow this  
Sir Sapo

AI in a 2D top-down flying game

Recommended Posts

I am making a "educational" WWII flight game for one of my classes at school and I have run into a problem. When I use my AI pattern (the enemies turn toward the player and fire when n range), the enemies just end up bunching together behind the player and all firing at once. How should I fix this problem , should I have the enemies choose random patterns every 10 seconds or should I just have enemies "activated" when the player gets close enough to them?

Share this post


Link to post
Share on other sites
I would have to agree with the approach of making the enemies aware of each other. Also, remember that enemies should be looking for "low deflection shots"... that is, they will not want to take a side shot, but rather one from the rear. I don't know whether you covered this or not, but in your explanation of "turn toward the player and fire", it seems like you were just saying "point and shoot". A 90 degree angle shot is almost guaranteed to miss. The desired position for the enemy should not be just "toward the player", but should involve being in the rear quadarant and pointing toward the player. This is a bit more involved with regard to trying to get into position... I don't know whether you are going to want to tackle it, but it will be a helluva lot more realistic. You will still have to deal with the bunching issue... in fact, even more so since that is where they will all be TRYING to be.

Share this post


Link to post
Share on other sites
This definitely sounds like case where the best route may be to identify behaviors you don't like, figure out what the AI should do instead, then figure out how to make that happen.

I would suggest taking a look at other games in the genre, potentially including 2d games.

Chains of simple patterns tend to be very effective in games like this. I would start by adding the ability to define maneuvers the AI can perform. You can attach these to rules (ie 'play an evasive maneuver if the player is behind me'), which may help a bit.

You may also want to add different states (attack, evade, observe) for different high/intent level decisions.

Share this post


Link to post
Share on other sites
Have you considered creating different AI's for your enemies?

Instead of having just one generic turn-n-shoot, write five or six different attack / defend patterns.

When a new plane is created set it to use one of the AI's, or for even more variety, let the planes randomly switch between tactics during flight. This should mix things up quite bit.

Some planes might want to get above the player and drop down on top.
Some might want to get behind the player (like you have now)
Others might go kamakazie and always fly directly towards the player.


If you want to be really creative you can further segment the attack patterns:

For example:

Create several different ways to aim.

i.e. shoot straight at the player (for a dumb pilot), lead the shot (for a smarter pilot), randomly shoot around the target (for a sometimes great, sometimes not pilot).

If you segment the program enough you should be able to get hundreds of different enemy plane styles using a small set of rules.

Will




Share this post


Link to post
Share on other sites
I agree with the idea of including different AI types in your game.

I believe this was how they did the old Pacman game. Each ghost had a different strategy for getting Pacman. One ghost would directly pursue, one would get out ahead of you and try to cut you off, another would hang around in a part of the maze that it knew you would need to come through eventually, etc...

Create different classes of enemies, each with a different strategy for attacking the player. This would solve your "bunching" problem and make the game more interesting to boot.

I also like your idea about "activating" enemies when the player gets close enough. In games I've written I've experimented with the idea of "spheres of influence". Enemies go on their merry way blissfully unaware of the player until some condition becomes true(usually related to proximity or line of sight) then they go into attack mode.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this