simple enemy AI
You guys know of good resources for beginning AI? My first goal is just to get monsters moving around in a randomish way. I'm making a little tile-based Legend of Zelda project and I just want monsters to wander around.
A good place to start with ai is with astar path finding. You probably want your monsters to avoid objects while they wander around. You can select random positions on a grid map and later have them finding food or enemies, etc.
This is educational:
http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior
http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior
To get that kind of movement its a simple algorithm:
And you simply update enemy position every now and then.
void updateEnemyPosition(Enemy& e){ Direction direction = randomDirection(); if(e.canMove(direction)){//canMove simply checks if the current enemy position + direction has a valid walkable tile e.moveUnit(direction); }}
And you simply update enemy position every now and then.
Quote:Original post by ConcentrateThat algorithm is unlikely to produce suitable results. Unless there's more to what you have in mind that what's shown above, the algorithm will most likely produce jagged, discontinuous paths that tend not to get anywhere (or if they do, do so slowly and inefficiently).
To get that kind of movement its a simple algorithm:void updateEnemyPosition(Enemy& e){ Direction direction = randomDirection(); if(e.canMove(direction)){//canMove simply checks if the current enemy position + direction has a valid walkable tile e.moveUnit(direction); }}
And you simply update enemy position every now and then.
@The OP: You're likely to have better luck with either a pathfinding-based solution, or with something like steering behaviors (e.g. wander + obstacle avoidance).
Quote:Original post by jykQuote:Original post by ConcentrateThat algorithm is unlikely to produce suitable results. Unless there's more to what you have in mind that what's shown above, the algorithm will most likely produce jagged, discontinuous paths that tend not to get anywhere (or if they do, do so slowly and inefficiently).
To get that kind of movement its a simple algorithm:void updateEnemyPosition(Enemy& e){ Direction direction = randomDirection(); if(e.canMove(direction)){//canMove simply checks if the current enemy position + direction has a valid walkable tile e.moveUnit(direction); }}
And you simply update enemy position every now and then.
@The OP: You're likely to have better luck with either a pathfinding-based solution, or with something like steering behaviors (e.g. wander + obstacle avoidance).
Your right, I was just trying to answer the OP question with a basic algorithm to move randomly, but actually there is a slight modification that one can make on that algorithm to make it more stable like so :
void updateEnemyPosition(Enemy& e){ Direction direction = randomDirection();int step = random(1,MAX_STEP); for i = 0 to step if( e.canMove(direction) ) e.moveUnit(direction);}
that should be a little better but there are algorithms out there that are much better than this. Above is just a starting point so you can have something on the screen.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement