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.
Bounding Box Collision Detection
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Bounding Box Collision Detection
- Attachments
-
- collisions.love
- (1.27 KiB) Downloaded 331 times
Re: Bounding Box Collision Detection
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.
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.
- rhezalouis
- Party member
- Posts: 100
- Joined: Mon Dec 07, 2009 10:27 am
- Location: Indonesia
- Contact:
[Response]PbP Translation
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.
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.
- Attachments
-
- delibrete-collisions.love
- LÖVE0.7.2 compatible
- (3.07 KiB) Downloaded 321 times
Aargh, I am wasting my posts! My citizenshiiiip...
Re: Bounding Box Collision Detection
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
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
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.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.
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 1 guest