dandorf Posted October 19, 2014 Share Posted October 19, 2014 AI enemies do things from time to time, etc ... It is time in my game, I have to create enemies. I do not know how to deal with the issue, I would like you to tell me some options there. How to make the enemy walk to the left and to the right, jump from time to time, etc .... that sort of thing. Thanks!! Link to comment Share on other sites More sharing options...
alex_h Posted October 19, 2014 Share Posted October 19, 2014 "do things from time to time" = Math.random() > 0.5 (for 50% chance of doing something this time) Link to comment Share on other sites More sharing options...
InsaneHero Posted October 21, 2014 Share Posted October 21, 2014 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 More sharing options...
Recommended Posts