Enemy AI: Progress


I now have a working enemy AI


I had a long train journey this week, which in between reading up on the history of China (its crazy - not the history so much, but trying to interpret it) gave us a chance to think about the Enemy AI and put pen to paper.

A quick in hindsight interruption first...

I mentioned in this post that when trying to find samples of an enemy field of vision script, I kept coming across threads posting to threads or links which no longer existed. Quite a few of them referred to a unity Stealth game which was done in Unity 4.3. If you try and follow the link to the original tutorial itself  , you will get an Access Forbidden 403 message. However, quite by chance I stumbled across Øyvind Strømsvik site. On there he has done his take on the stealth game which works in Unity 5.x . I really wish I had come across this at the start, as it is a great example of not only the FOV but practically everything else. I highly recommend taking a look at it.

Back to the Enemy AI; from my previous experience as a programmer, I am used to everything being started from either a singular while wend loop or a singular form. From here, all other objects are called, initiated, interacted, destroyed etc until the wend condition is met, or the form is closed.

I am used to creating collections of my objects and managing their information through it, whilst managing the object themselves with properties and methods. I am also used to being able to set global variables which I can reference and change from wherever I like. With Unity, I am finding it somewhat alien in how everything fits or should fit together, but that will come with time.

In my last post  I put my head in the firing range and said I don't believe my code to be wrong, but rather the order of my code. On my train journey, I started doing simple flow charts from each of the enemy states.  I am also using various timers in my game and doodled some rough timeline scenarios. Then finally to try and wrap everything together, I did some logic trees.  Going back to my state machine, it now looks like the following.



I have added the level breakdown along the top, to help me track things easier in the logic. One of the changes from my original plan is Inspect has now been replaced with Alert, and Attack has been broken down into Chasing and Shooting. A lot of this change was down to semantics from working it through on paper and this approach continues going down deeper into the logic.

Armed with this, I started renaming, chopping and re-ordering my code. It is far from polished, but I am happy enough to start progressing other elements of the game.

In no particular order;

  • User interface 
  • Shooting mechanics 
  • Ammo collecting and reloading
  • Player controller 
  • Game camera 
  • Level design 
  • Game balancing 
  • Music and sound design
  • Animation




Comments