Tile based collision detection woes
Posted: Mon Aug 25, 2014 4:27 pm
Hi,
I'm having trouble with detecting collisions in a tile based game. I am basically following the steps in this excellent writeup (type #2):
I've attached a love file with my code, so if anybody could spare me some hints... I've disabled gravity (line #186 in player2.lua) and to reproduce my problem, just hit the up arrow key. You'll see the player just clip through the tile. I'm sure it's somewhere in the detection of the collidable rows and columns, but I have no solution to how to fix that. I've been looking for a solution in this direction, but now I'm in dire need of a few pairs of extra eyes.
(Please note that the code is a WIP and is far from beautiful or finished. I'm a beginner in Lua (and game programming), and things obviously need polishing here and there)
I'm having trouble with detecting collisions in a tile based game. I am basically following the steps in this excellent writeup (type #2):
- First, I check the rows and columns which are eligible for collision, based on the player's position (in the attached demo file, the red and green lit rows).
- In those rows and columns, I'm checking for the nearest collidable tiles to the left, bottom, right and up positions (the white lines in the demo).
- The bounds I calculated from that are used to determine whether the player possibly hits something to his left, bottom, right and up positions.
- When the player did hit something, I set the player's position to the appropriate bounds that were hit.
I've attached a love file with my code, so if anybody could spare me some hints... I've disabled gravity (line #186 in player2.lua) and to reproduce my problem, just hit the up arrow key. You'll see the player just clip through the tile. I'm sure it's somewhere in the detection of the collidable rows and columns, but I have no solution to how to fix that. I've been looking for a solution in this direction, but now I'm in dire need of a few pairs of extra eyes.
(Please note that the code is a WIP and is far from beautiful or finished. I'm a beginner in Lua (and game programming), and things obviously need polishing here and there)