Jump to content
  • Advertisement
Sign in to follow this  
javasirc

text-game AI grid pathing

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

Ive been working on a text-game with a 2d scrolling map and im almost finished. But i need to apply some AI stuff. I spent about an hour and a half trying to figure out an equation and checked a few threads about it. What im trying to do is make an AI mob chase my character. Basicly if i cast a spell at it, or get in a cirtain radius of it, a boolean variable 'isHostile' is set to 'true', making him come after me. But im stuck figuring out an equation for pathing on a grid map. Here an example: -----------***x10**** -01234567890123456789 0-------------------- 1-------------------- 2--@x---------------- 3----xxx------------- 4-------xxx---------- 5----------xxx------- 6-------------xxx---- 7----------------xM-- 8-------------------- 9-------------------- @ = my character (point: 2,2) M = the mob (point: 7,17) x = a square the mob should land on, starting from right to left PS: im pretty sure the x's are right, i mapped it out on grid paper Does anyone know an equation to solve this? Also if you could supply an example using the points about, that would be real helpful too. Thanks for reading, and i hope someone else will find this useful. EDIT: it took all the spaces in the graphs out, so '-' represents a space

Share this post


Link to post
Share on other sites
Advertisement
Thank you so much! Its a lot more work than i thaught lol. A lot of reading and note-taking, but will be worth it.

Share this post


Link to post
Share on other sites
Quote:
Original post by javasirc
Thank you so much! Its a lot more work than i thaught lol. A lot of reading and note-taking, but will be worth it.

You should be able to reuse a fast line rendering algorithm for anything that moves in a straight path, like projectiles, and possibly to compute visibility and illumination between map cells.
For the original application, however, computing a whole line is probably wasteful because while the mob is chasing the target moves and the straight shortest path is invalidated; you actually need to compute individual steps of the mob, choosing one of its 8 adjacent locations.
Without obstacles, you can avoid A* or even more complex approximate pathfinding and simply compare the distance between the target and the two adjacent cells in the appropriate octant (only one choice when the target lies on the same row, column or 45° diagonal as the mob).

Share this post


Link to post
Share on other sites
Google for roguelike, and line of sight algorithm. If someone would know this it would be them. IIRC they compute multiple lines of sight per one step. And yes there is a little catch called a creature shouldn't interrupt its pursuit just because it lost a line of sight of a character.

BTW term mob is from MUD development. If you'd like to write a something less primitive, you might like a idea of a self sufficient player independent creatures.

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!