Jump to content

AI of enemies, do things from time to time, etc ...


dandorf
 Share

Recommended Posts

I set up a state machine and use random (as alex_h says) to switch to different states.  This lets you make sure that a state has finished before it switches to doing something else.  So for walking left, you might have a timer that counts 5 full animation cycles before it stops (unless it bumps into something).

Sometimes you don't want it to do the same thing twice in a row (like jump for instance) so you can add cool-down counters.

There are a lot of ways of doing AI for your enemies, but I've always found the most interesting results come from coding up something very simple to start with and then just adding a new rule every time you notice an enemy do something dumb.  If you happen to think "wouldn't it be cool if the enemy did X?" this approach makes it pretty easy to experiment with a few rules to add a new behaviour too.

One word of warning: if you are doing very complex systems, the code can end up quite spaghetti-like and that makes it very hard to debug... I had no problem using this approach for the AI in Aztec God Game, but when I wrote the AI for Stratego it became too messy and I had to refactor the whole thing.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...