   Side scroller AI... state engine needed?
  Hey guys, I just recently started a side-scroller project and I just finished getting the kinks outta my animation class and did some basic collision detection.  I figured I should work on the "battle" system now.  I'm trying to do something akin to the X-men or Simpson sidescroller (arcade style).  But how should I do the AI?  I have a very good AI book called "Game programming AI by example" which I've learned a couple of things.  So that presents me with a couple of questions:1.) Do I need to use a Finite State Machine?2.) If so, should I use the one in the book?  That seems a little too lengthy, is there anyway I can minimize the code and still have it be fairly effective?Any links, or general advice would be great.  Sometimes I'm sorta vague without meaning to, so let me know if you need more information to better assist me.  Thanks :)   
  Of course you don't need a finite state machine. Personally, I think states are usefull when your enemies and objects have a lot of different states, that determines the way they react. And since a sidescroller usually contains enemies that follow a predefined path while continually firing their weapons, there's little different states really so I see little reason to implement a fully-fledged state system.For example, a game where an enemy can get irritated after being shot, or get sleepy after not having seen an enemy for a long time, could use a state machine much better. Each state defines his behaviour for that state, and the possible transitions to other states. Helps you divide the various behaviours and thus clear things up.So let's make this clear first: what behaviour do you want for your enemies?   ;  It really depends on how you want to create your AI.  In the case of a side scroller, i'd suggest implementing a relatively simple hard-coded AI.  It doesn't need to be adaptive, it just needs to be able to handle a certain set of pre-defined conditions. <reaches for mouse.... realizes that i'm on a notebook and that there is no mouse to reach fore, gives up>   ;  Well I'm still not sure if I'm going to use a state machine, but after looking at the code once again I realize it isn't too bad to impliment and would fit into my current system fairly easily.  I guess what I want (as of right now) is to be able to have an enemy just go up and attack the player.  Maybe give an enemy a few different attacks.  And there is the possibility of having a commander (who would send orders to the enemies on screen) *shrug*I basically don't want anything too complex NOW, however I could see myself (assuming all goes well) making this  a lot more complex if I had the time.Does that help at all?   ;  Whether that helps is a distinction only you can make.  All I can tell you is that I reccomend you avoid the complexity of a state machine and simply script the AI.  It is much simpler, and most certainly appropriate for a sidescroller   ;  Aack server errors -_-Thanks for the reply guys.medevilenemy, can you expand on what you would do in terms of hard coding?And if I were to use a state machine, what state would I use as a default?  IDLE??   ;  By hard code I mean you simply run through all the objects which have AI, upon initialization you should read in the specific AI personality of each object.  When you run through the objects, you should simply include a switch statement along the lines ofswitch(objectpersonalities) // Where i is the number of the object{   case 1: // as in the personality designated as number 1 personalityone(); break;   // ETC}within the "personalityone" function, and all the other personality functions, you should simply analyze variable data values (the basic stuff that would be stored within an object) and code in instructions for what the object should do upon certain sets of variable data.for example, in my game a couple of my AI personalities detect whether the player has fired at the object which uses it.  I have coded the AI so that it moves the object a certain way under these conditions.;  States really are just a way to divide AI behaviour into different chunks of code, where each chunk determines how the AI behaves in that state, and when it has to change state. If your AI is quite simple, a switch case and a simple int that holds the state number (or, enumeration, whatever floats your boat) probably suffices - the idea behind it is essentially the same.State machines aren't the AI itself. They help structuring your AI behaviour. You still have to define the AI in these states. Try to think about what different states of behaviour your enemies could have. Perhaps sketch out a diagram.I think your enemies will have a 'normal' mode, where they attack you and follow their path. Perhaps they have a 'flee' mode, where they just try to dodge your fire and get out of there alive. They could change from flee mode to normal mode after a command from the commander unit, and change back when taking damage, for example. That would make 2 states. I'm sure you have a better idea about your enemies behaviour so I'll leave the rest up to you. Just know that a FSM isn't necessary - but it may well be an interesting concept to play with. ;)   ;  if your wanting to add more later on a FSM can't really do much harm though   ;  hmm, i've been working on my state machine and general AI the past day or two and right now i have three states:idle, think, and attacki have some helper methods:Jump()moveTowardLocation(float x, float y, float stopDist)it is SORTA working, i'm trying to make a jump-attack right now;  it's pretty hard :-pall the idle state does is just execute the changeState and changes the state to thinkthe think, apon entering checks the distance between the entity and the player(s) and chooses a player to be its "target", which it does by calling checkDistance()then when the think state is active and excuted it will (eventually) determine what choice to make (attack, fallback, holdposition etc) and then does a moveTowardLocation, which returns a bool, and takes in the target's x/y position and a distance which will effectively be the range, if the target is "in range" then it will perform the operation... (my thing right now) is an attack, so it changes the state to the attack statethen, when it enters the attack state it determines what attack it is doing, and performs the necessary actions, this is where jump is called... however i don't think it is workin, so i'm probably going to make jump into a state, but i'm not sure :-/basically the enemy is switching to the jump animation when in the air, and it is moving, but i can't seem to get it to be a jump like you see in old arcade scrollers (think teenage mutant ninja turtles)anyone have any ideas on that, or just in general anything i could do, or just share some knowledge about similar things you mighta done?  i need some advice/encouragement etcTHANKS again :)  [this post was long... sorry]Edit:  my other problem that i'm trying to think of now, is how to make it so that only two enemies (entities) are on each side of the player... right now if i let the enemies do as they wish they just all group up by the player on one side (i guess i need some collision code between enemies?)...  bleh, AI is hard!!! (but sorta fun/interesting)does any1 know if arcade sidescrollers used flocking? i don't think that'd be applicable to me, but hey, i can always be persuaded... :D   