Jump to content
  • Advertisement
Sign in to follow this  
flodywan

simple enemy AI

This topic is 2853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Concentrate
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.
That 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).

@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).

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
Original post by Concentrate
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.
That 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).

@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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!