Collision detection: collision box extends up and left of box

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
darkfire613
Prole
Posts: 2
Joined: Fri Apr 29, 2016 5:26 pm

Collision detection: collision box extends up and left of box

Post 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!
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

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

Post 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())
darkfire613
Prole
Posts: 2
Joined: Fri Apr 29, 2016 5:26 pm

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

Post by darkfire613 »

Thank you so much, that took care of it!
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests