Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Alan Kemp

Movement on tile maps, and how to not get stuck on corners?

This topic is 5634 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, I am writing a bomberman clone, which as you probably all know takes place on a square, tiled grid. Each of my tiles in 32x32, and the characters are also 32x32 sprites. Now each frame I move your sprite with:
if (keydown(UP))
    sprite.y += speed;
if (keydown(DOWN))
    sprite.y -= speed;
And as you can imagine the same for left and right. My problem is this, say you are approaching a crossroads in the map, heading left to right, and you want to turn up the map, you are holding right and up together, but go straight past the opening. Why? Because sprite.x += speed put you a couple of pixels past the opening, so you were not allowed to move up by the collision detection code. I hope what I am trying to say is clear. This must be a problem for any tile based game where the corridors are the same width as the main character, how do people deal with this? Do you fudge it, so if you are within, say 2|3 pixels of a corridor you go down it? Alan

Share this post

Link to post
Share on other sites
I found using a collision rect that is not the same size as the sprite works pretty well for this. Most of the time my sprites collision rect only encompases a rectangle a few pixels right of the left edge to a few pixels left of the right edge and from about the middle of the sprite to the bottom of the sprite.

+-----+ <-source rect
| \0/ |
||/_\||<-collision rect

another way to do it is only allow movement of a whole tile at a time. Kind of like the old NES rpgs. 1 tile, 1 occupant, 0 hassle

Share this post

Link to post
Share on other sites

  • 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!