Page 1 of 1

Collision detection: collision box extends up and left of box

Posted: Fri May 13, 2016 6:45 pm
by darkfire613
Hi everyone, I'm working on a simple top-down tile based dungeon crawling game (think the original Legend of Zelda). I'm trying to use the bump.lua (https://github.com/kikito/bump.lua) library to handle collision detection, although I encountered this exact same problem using the basic bounding box function (https://love2d.org/wiki/BoundingBox.lua) as well.

Basically, the tile with collision in the world seems to have its collision rectangle extended infinitely above and to the left of it. That is, if I try to move my player above the tile or to the left of it, it will still collide on nothing and prevent me from moving. I really have no idea what might be causing this, but you can see the entire source on GitHub here: https://github.com/darkfire613/undercity

Any wisdom on this would be greatly appreciated!

Re: Collision detection: collision box extends up and left of box

Posted: Fri May 13, 2016 8:37 pm
by veethree
One thing that immediately stands out to me is this line

Code: Select all

world:add(Player, Player.x, Player.y, love.graphics.getWidth(Player.img), love.graphics.getHeight(Player.img))
What it's doing is setting the width and height of the players collision box to to the width and height of the window. That's what love.graphics.getWidth/Height does. I believe what you wanted to do is get the width and height of player.img.

For that you would do

Code: Select all

world:add(Player, Player.x, Player.y, Player.img:getWidth(), Player.img:getHeight())

Re: Collision detection: collision box extends up and left of box

Posted: Fri May 13, 2016 9:14 pm
by darkfire613
Thank you so much, that took care of it!