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

Detecting Tile Solidity

Started by
2 comments, last by GameMusic 24 years, 5 months ago
How do you reliably detect whether a sprite can move through an area of the map in a tile-based sidescroller or overhead view game? I''m designing a game with an engine like this, and I am occasionally able to move the edges of a sprite so that they overlap a solid tile, if I''m moving very quickly and in a diagonal direction. I''m currently using a somewhat "quick fix" method of detecting tile solidity. If a tile is detected near the sprite, it moves the sprite one pixel at a time, stopping as soon as a collision with a solid tile is detected, or the desired distance has been travelled in the x and y directions. I did it this way so that, no matter how thin a solid tile or platform is, or how fast a sprite is moving, it will never "jump" past a tile without detecting it. Unfortunately, since x and y corrdinates have to be incremented separately, there can be some errors when a sprite is moving very quickly and at an angle. My current plan is to have a special case for diagonal movement, with the y-increment being a ratio so that the function doesn''t assume a 45° angle. However, this seems somewhat convoluted and slow, so I suspect that there are many other alternatives out there. Any help would be greatly appreciated.
Advertisement
You could just check how much overlap exists from the sprite in the tile and subtract that from the sprites coordinates. Do this once for each direction and it should place them at the edges of solid tiles, even diagonal.



Jim Adams
Game-Designer/Author
tcm@pobox.com
http://www.lightbefallen.com
http://www.basicelectronics.com
Thank You! This is a big help. I''ve put this method into my program, and now I can finally focus on other parts of it.
Thank You! This is a big help. I''ve put this method into my program, and now I can finally focus on other parts of it.

This topic is closed to new replies.

Advertisement