Public Group

# Help with AI!

This topic is 4191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi again. I need some help with AI. Im making a simple(really simple) 2d shooter game, and im trying to figure out how to move the enemies. So far i've managed to make them scrolling (x axis) , but im thinking to add more complex movement functions. Any ideas how to do it?

##### Share on other sites
You said how to move. Is the problem actually how to move them or is the problem coming up with an AI algorithm that tells the entities when to move?

-me

##### Share on other sites
I'll just preempt my question and assume you mean how to design the AI. =)

One possible architecture would be:

1) a behavior chooser (a container for behaviors)
2) a set of behaviors (that live in the behavior)

Each behavior has a couple methods:

virtual void start();virtual void update();virtual bool canRun();virtual void stop();

Start does whatever happens at the start of the behavior (initiate firing, jump, start pathfinding, whatever)

update just updates the behavior (does it need to path follow, continue shooting) It should also check for end conditions (is the player dead, is he no longer near me, did i finish jumping, etc).

canRun() is a heuristic for if the behavior is an acceptible choice for the moment.

stop just ends the behavior

Then basically each frame the BehaviorChooser checks to see if a behavior is running, if none are running collect a list of all behaviors that canRun. then choose randomly between them and start the selection.

Might be overkill for a 2D shooter but it's a nice framework. =)

-me

##### Share on other sites
@Palidine:
Thanks , but thats kinda...complicated...i dont think that i can do that yet.

Quote:
 Original post by PalidineYou said how to move. Is the problem actually how to move them or is the problem coming up with an AI algorithm that tells the entities when to move?-me

Sorry , i thought that it has to do with AI...

What i actually want is to make them move in different patterns.

##### Share on other sites
I would say that your question does pertain to AI as you are trying to give your enemies the illusion of intelligence.

The question becomes what level of intelligence you are after. If you just want some simple “paths” then making a simple system involving nodes and linear interpolation might work just fine for your purposes.

To make this sort of a system you would need a list of points. You would start at the first point and use linear interpolation to move to the second point, then the third, ect. Then based on the path options you could choose to go back to the starting point.

Then there is always the option of using trig to help compute path nodes…

Really though hard paths are not the best way to deal with enemy intelligence. I would recommend representing each enemy as a finite state machine.

Each enemy would have a number of “states” like “patrolling”, “attacking”, and “escaping” and a number of rules for going from one state to another. To go from the “moving” state to the “patrolling” state, a rule could be to test if the player is the line of sight and if the enemy has ammo. If the player is in line of sight and the enemy doesn’t have ammo then we would do the “escaping” state. If the enemy is in the attacking state and then runs out of ammo then you would go to the escaping state. If the enemy loses sight of the enemy and is in attacking state then you would go to the patrolling state.

The key is that the enemy can only be in one state at a time and each state has different behaviors. By adding rules and by adding states, we can build a large layer of complexity.

Personally I like this tutorial on the subject: AI-Junkie agent tutorial

I hope this helps!

##### Share on other sites
Quote:
 Original post by 3Dgonewild@Palidine:Thanks , but thats kinda...complicated...i dont think that i can do that yet.

Heh. fair enough.

If you just want different movement patterns then code up a few and choose randomly between them.

If the question is how to make different patterns first define the "different patterns" that you want to make. You can't design code to make something happen unless you know exactly what you want. If you could describe in more detail exactly what type of movement you are after that would be a big help.

If you need help coming up with those types of movement could you describe your game a little more? What are the enemies: infantry, tanks, airplanes, etc.

-me

##### Share on other sites

If i turn my game(actually a cube vs mad triangles) into a space shooter? it will be alot easier right?

edit:
I wanted to make a shooter like "metal slug" ..but i guess i need more practice.
So , im going to make a space shooter.

##### Share on other sites
Well yes, that makes things easier from an AI perspective. Chances are you would just need to "move" and "shoot".

I personally feel that you should attempt to make the AI becuase it will give you experience in the area and it will give you a sense of accomplishment when you pull it off :).

##### Share on other sites
But for now , what kind of math functions i'll have to use?

##### Share on other sites
Never;mind.
I've just installed mame and played few games.
I think i understand how they move!

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632930
• Total Posts
3009290
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!