Page 1 of 1
Bounding Box Collision Detection
Posted: Mon Dec 05, 2011 12:13 pm
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.
Re: Bounding Box Collision Detection
Posted: Mon Dec 05, 2011 5:32 pm
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.
[Response]PbP Translation
Posted: Tue Dec 06, 2011 1:11 am
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.
Re: Bounding Box Collision Detection
Posted: Mon Dec 12, 2011 7:23 am
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.
Re: Bounding Box Collision Detection
Posted: Mon Dec 12, 2011 7:23 am
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.
Re: Bounding Box Collision Detection
Posted: Mon Dec 12, 2011 7:51 am
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.