Tile Collision Detection As3
- businessman9774
-
businessman9774
- Member since: May. 10, 2012
- Offline.
-
- Forum Stats
- Member
- Level 04
- Game Developer
Hey guys, I'm having a lot of trouble getting the collision detection correct for a platformer game I'm making. I'm stuck even on the most basic detection I need for the player and the walls/floors. I can get it working okay but not perfectly so I figured I'd ask you all how you would go about it (I think I'm making it much more complicated than it needs to be).
So, I have a vector containing all the tiles for a level, all these tiles have x, y, width, height properties, and I have my player object with his x, y, width, and height. I assume I need to iterate through the tiles and compare their locations to the position of my player and adjust the player's properties according to what he's touching, but I can't seem to get it to work right in both the x and y direction at the same time. Any tips would be greatly appreciated.
- Sam
-
Sam
- Member since: Oct. 1, 2005
- Offline.
-
- Forum Stats
- Moderator
- Level 19
- Programmer
You have the x, y, width and height. They might conform to some grid in a "tile" kind of way, but they might not, and it actually doesn't matter. You can use standard box collisions to check if a collision occurs. Here's a pretty quick and informative video on it.
Resolving that collision is as simple as moving the object(s) in the opposite direction they were moving until the collision isn't happening any more.
Alternatively (or additionally, in certain cases), you can pre-emptively check if a collision will occur if the object were to move as much as it wants to. If a collision would happen after the movement, just don't allow it to move at all, or move it as much as it can without colliding.
- GeoKureli
-
GeoKureli
- Member since: Apr. 1, 2003
- Offline.
-
- Forum Stats
- Supporter
- Level 19
- Game Developer
This blog I made | This game sucks | FlxGreed | Home Run Swingers: Rhythm Baseball
many typos

