Tile based collision detection woes

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Azzkikr
Prole
Posts: 5
Joined: Mon Aug 25, 2014 4:01 pm

Tile based collision detection woes

Post by Azzkikr »

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):
  1. 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).
  2. 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).
  3. The bounds I calculated from that are used to determine whether the player possibly hits something to his left, bottom, right and up positions.
  4. When the player did hit something, I set the player's position to the appropriate bounds that were hit.
All is well at first sight. I can jump around, 'gravity' works, I hit all kind of bounds I can think of. But after some thorough testing (I love me some jumping around when that worked :)) I found out I could jump *through* a tile when the tile is approached at a certain angle. Specifically, when the player is moving 'into' the corners of a tile. I must be missing something somewhere, although I got no clue where I should fix it, or if my attempt at calculating the bounds for collision are even okay.

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)
Attachments
woes.love
Crappy WIP
(474.93 KiB) Downloaded 157 times
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Tile based collision detection woes

Post by Tjakka5 »

I'd say you should expand the collision detection area around the player by one pixel on every side.
That might fix it.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests