Jump to content
  • Advertisement
Sign in to follow this  
3Dgonewild

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


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

Quote:
Original post by Palidine
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


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

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

Share this post


Link to post
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 this post


Link to post
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.

Perhaps then just a simple state machine like shadowisadog laid out.

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 this post


Link to post
Share on other sites
Hmm..advanced stuff!.

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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!