Bounding Box Collision Detection

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
Delibrete
Prole
Posts: 37
Joined: Mon Dec 05, 2011 11:51 am

Bounding Box Collision Detection

Post by Delibrete »

Hello,

I have been trying for a very long time to understand the concept of bounding box collision. I read this http://love2d.org/wiki/BoundingBox.lua and I tried it out but for some reason I'm unable to get collisions to work.

Can somebody please explain to me the theory behind bounding box collisions? or provide me with an example of a bounding box collision?

Right now I just want a game where a small square moves around and collides with other squares. Lua is very new to me as I'm mainly used to Java programming.


*UPDATE*

I managed to solve some of the problem, but I'm getting an issue where it stops just before it hits the wall. Here is my love file.
Attachments
collisions.love
(1.27 KiB) Downloaded 332 times
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: Bounding Box Collision Detection

Post by Ensayia »

The problem with making your own collision is not in the detection, but rather the resolution. It's pretty easy to tell if two entities are colliding but it's much harder to make them react with appropriate timing and results. I ripped my hair out for weeks trying to work on collision detection on an old Tank game project (you can search it on the forums and read all the update notes) and still didn't get something that was 100% reliable.

More or less, it's a balancing act of timing, frame rate, and entities interacting and colliding with other entities in a way that makes sense on screen. I'm sorry this post doesn't help much but physics and collision are a tricky beast. My current project is on hold due to a custom physics lib made by a friend not being accurate enough for some mechanics I want, thus I'm waiting till LOVE 0.8.0 is released and switching over to Box2D.

Good Luck in your endeavors.
User avatar
rhezalouis
Party member
Posts: 100
Joined: Mon Dec 07, 2009 10:27 am
Location: Indonesia
Contact:

[Response]PbP Translation

Post by rhezalouis »

Hi Delibrete, welcome to the LÖVE forum!

As mentioned by Ensayia, your box stops just before it hits the wall because its next position is already in the wall and your conditional forbid it to move at all.

If you want them to collide, you have to pay attention to the player's movement (dx), which in your application is equals to speed * dt. The problem is that the delta time is a floating point which causes slight decimal difference between the player dx with the grid's integer coordinates; and this would ultimately create some gap when the player tries to move towards a wall from a non-integer position.

I wrote a Prototype-based Programming version of your code; I hope you could get something out of it. :ultrahappy:
Attachments
delibrete-collisions.love
LÖVE0.7.2 compatible
(3.07 KiB) Downloaded 322 times
Aargh, I am wasting my posts! My citizenshiiiip... :o
Delibrete
Prole
Posts: 37
Joined: Mon Dec 05, 2011 11:51 am

Re: Bounding Box Collision Detection

Post by Delibrete »

Thank you for your attachment, I noticed a few errors in my code. Soon enough with the help of my brother I'll be able to solve this problem and I'll post up a tutorial.
Delibrete
Prole
Posts: 37
Joined: Mon Dec 05, 2011 11:51 am

Re: Bounding Box Collision Detection

Post by Delibrete »

Thank you for your attachment, I noticed a few errors in my code. Soon enough with the help of my brother I'll be able to solve this problem and I'll post up a tutorial.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Bounding Box Collision Detection

Post by ivan »

Delibrete wrote:I managed to solve some of the problem, but I'm getting an issue where it stops just before it hits the wall. Here is my love file.
You may want to look into 'continuous' collision detection which is basically figuring out the time of impact and resolving the collision so that there is no gap/overlap between the colliding shapes.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest