Jump to content
  • Advertisement
Sign in to follow this  
EternityZA

Simple AI for 2D grid based game.

This topic is 2510 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

Hi.

im creating a dead simple 2D game. the game consists of a grid that is15x11. each entity takes up 1 square on the grid. The AI for one particular type of enemy should find a path to the player and move to him. each square in the grid is either open or the enemy to pass through or its not. Enemies pass through each other so they can ignore each others existance.

What method would i use to implement this path finding? simplicity over performance. its a tiny game world after all.

Share this post


Link to post
Share on other sites
Advertisement
If there are obstacles (walls) then A*. Otherwise just check to see left/right up/down and move 1 space in the right direction.

Share this post


Link to post
Share on other sites
There is walls. sorry i didnt type that very clearly in the OP. im having trouble googling A* since google ignores the *. is there a full name for it?

Share this post


Link to post
Share on other sites
There is walls. sorry i didnt type that very clearly in the OP. im having trouble googling A* since google ignores the *. is there a full name for it?[/quote]
A star.

Share this post


Link to post
Share on other sites
A* is very good, though slightly advanced. What i did in my game is giving my tiles an extra int for path numbering. Then from the destination put all adjacent tile n=1, then from these adjacent tiles n+1 for there adjacent tiles and repeat this. Stop when you are calculating the tile your standing on. Then move to the lowest number in the adjacent tiles. This technnique works surprisingly well.

But then again, A* can do a lot more once you get the hang of it.

Share this post


Link to post
Share on other sites
Here's an A* javascript script http://www.battlefor...pathFinding.php demonstration and source.

I haven't used it because I haven't figured out which way I'm going with the map yet(generated tiles vs single image, top down vs isometric[in an html5 game]). Currently I just run around on a background image and use tangent/sin/cosine to move objects on layers above while sliding the bg sprite images based on the sin/cos the object is moving...

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!