🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Pathfinding and moving the characters

Started by
0 comments, last by wiseGuy 24 years, 6 months ago
Hello all. At present I am having a few headaches over pathfinding, using a very simple square based map. What happens is this: * When the player click on a tile, the pathfinding engine works out the shortest path there, and stores it in an array called directions[]. (each element is a #defined Direction, ie UP, UP_LEFT * Every frame, a MovePlayer() function is called, which looks in the directions[] array based on the CurrentDirection. It then moves the character a certain amount based on the direction, and when it has moved 64 pixels (a tile), it increments the CurrentDirection. Note that it only moves the player a small amount each frame! This would work fine, although it would result in very strange walking, because if the player clicked on the edge of a tile, the sprite would walk to the very centre. Also, when the sprite first starts moving, it needs to be in the centre of the tile, otherwise it could appear to walk through a tile if it moves diagonally. How could I overcome this without the sprite moving stupidly? (stupidly = moving to the centre of the tile first, then moving to the centre of the last tile, then moving to an offset. This would look very stupid because the sprite might move backwards to get to the centre, then start off in the right direction! very stupid indeed) I hope someone can help! wiseGuy
Advertisement
If a map cell includes so much room for the character to stand in, maybe you should sub-divide the cell for purposes of moving around. Super-impose a 3x3 "movement grid" on each map cell.


DavidRM
Samu Games

This topic is closed to new replies.

Advertisement