bump.lua - minimal collision detection lib

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: bump.lua - minimal collision detection lib

Post by Roland_Yonaba »

I tried it,that's impressive!
Well done!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: bump.lua - minimal collision detection lib

Post by kikito »

Version 1.2 of the lib is out!

Changes:
  • Added bump.addStatic for items which need to be "collided against", but otherwise are not very interesting - useful for static scenery, for example
  • Added bump.collect to get the items in a given region
  • Changed the way collisions are prioritized - the lib uses the maximum collision surface i now. Before it used the minimum distance to the center.
  • Fixed an issue in which the lower or right border of a rectangle could "overflow" to the next cells, decreasing performance.
  • Other minor bugfixes and some code cleanup.
I've attached a demo of v1.2 in the OP, and left the 1.0 version there, too. If v1.0 run slowly on your computer, chances are 1.2 will be better (to be honest on my machines they run at similar speed).
When I write def I mean function.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: bump.lua - minimal collision detection lib

Post by Roland_Yonaba »

I love you that. :crazy:
Works well for me. Can I ask questions ?

In a nutshell, how does it work (i haven't digged in the code yet) ?
Are you making some sort of space partitionning ?
Actually, bump stand for collision checking with rectangle-bounded shapes. Have you plans to add support for more shapes ? Points, Segments, lines, Circles, triangles, n-shaped polygons ?
Actually I was looking for some little "physics" support...I mean, looking at the attachment, the box should fall. But it won't....

But once again, that's amazing. Very responsive, and fast, too.
Great work, thanks sharing! :awesome:
Attachments
test.png
test.png (45.46 KiB) Viewed 3875 times
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: bump.lua - minimal collision detection lib

Post by kikito »

Roland_Yonaba wrote:I love you that. :crazy:
:ultrahappy: thanks!
Roland_Yonaba wrote: In a nutshell, how does it work (i haven't digged in the code yet) ?
Are you making some sort of space partitionning ?
Ok. Let me try to explain.

Bump divides space into squared "cells". Cells are created "on demand", as needed, so you don't need to specify "world boundaries" or anything. Empty cells get garbage-collected when the collector runs. They have a default side length of 128, but that can be changed in bump.initialize().

Appart from the cells, there are "items". Items are the objects of your game. The player, bullets, enemies, ground tiles, etc. In bump, at least for now, an item is defined as "something that has a bounding box". Items' bounding boxes can change in position and size over time. This is called "updating". When an item is added (or updated) bump calculates which grid cells it "touches". For each item, it knows what cells it touches. For each cell, it knows what items touch it.

That's the nutshell. Once you have the list of items with their cells, and the list of cells with their items, you can check for collisions very efficiently.

The way the collisions are calculated is relatively simple. However, the order in which the collisions have to be triggered, is tricky as hell. When a player walks over a tiled ground, is surprisingly complex to tell it "consider the tile right under your feet first", so it doesn't consider the "next tile" as a wall, and stops walking. I think I've managed to get it more or less ok, but it's still not 100% perfect. On 1.2 I've basically redone this whole prioritisation thing, as well as added "static" items (which

At the end, what you get in the bump.collision callback is a pair of elements colliding, and a displacement vector. The displacement vector is literally the smallest movement you have to make in item so it doesn't collide with item2 any more.
Roland_Yonaba wrote: Actually, bump stand for collision checking with rectangle-bounded shapes. Have you plans to add support for more shapes ? Points, Segments, lines, Circles, triangles, n-shaped polygons ?
I like bump's simplicity. For now, it suits my needs. I don't plan to include shapes. For now, it'll remain bounding boxes-only.

I do plan to include more types of queries. Right now you can only say "give me the items on this rectangular region" (with bump.collect). I'd like to be able to say "give me the items containing this dot" and "give me the items on this segment". But I have to think about how to do that properly.
Roland_Yonaba wrote: Actually I was looking for some little "physics" support...I mean, looking at the attachment, the box should fall. But it won't....
Ah, but the image you have shown could also be a car seen from a top-down perspective, and the block next to it a little building :). Adding physics would overcomplicate the lib IMHO.

Thanks for your comments. Let me know if I can be of assistance in any other thing! (although I'll leave the country in 2 days, and I'll be quite busy until september)
When I write def I mean function.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: bump.lua - minimal collision detection lib

Post by Roland_Yonaba »

That was really helpful, thanks a lot for explaining.
I'll sit someday and review your source, may grasp a lot from this.
User avatar
Nsmurf
Party member
Posts: 191
Joined: Fri Jul 27, 2012 1:58 am
Location: West coast.

Re: bump.lua - minimal collision detection lib

Post by Nsmurf »

is it compatible with Advanced tile loader? I couldn't make much sense of the source code, and the demos don't run :( (Do they use canvas?)

If it is not compatible, would it be hard to make a fix?

i would think something like this: (pseudo-code)

Code: Select all

(in love.load)

loop through all tiles (y positions)
loop through all tiles (x positions)

create bump object at the right x and y position

end loop
end loop
But i was having a hard time understanding bump, so it would be great if someone pointed me in the right direction with writing a something to the effect of my pseudo-code.

thanks in advance,

Nsmurf

P.S.

Looks like a awesome library, i just hope i can use it :awesome:
OBEY!!!
My Blog
UE0gbWUgd2l0aCB0aGUgd29yZCAnSE1TRycgYXMgdGhlIHN1YmplY3Q=
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: bump.lua - minimal collision detection lib

Post by kikito »

Nsmurf wrote:is it compatible with Advanced tile loader? I couldn't make much sense of the source code, and the demos don't run :( (Do they use canvas?)

If it is not compatible, would it be hard to make a fix?
Hi,

Probably it is. I have not used ATL, so I'm not 100% certain, though. I can't provide a full implementation, though. I am on holidays at the moment. Good luck!
When I write def I mean function.
User avatar
Nsmurf
Party member
Posts: 191
Joined: Fri Jul 27, 2012 1:58 am
Location: West coast.

Re: bump.lua - minimal collision detection lib

Post by Nsmurf »

OK, thanks!

Can you provide me with a link to some sort of documentation though? Sorry if it is in an obvious place, I've looked, and I can't find it :(
OBEY!!!
My Blog
UE0gbWUgd2l0aCB0aGUgd29yZCAnSE1TRycgYXMgdGhlIHN1YmplY3Q=
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: bump.lua - minimal collision detection lib

Post by kikito »

Documentation for bump is this forum thread, as well as the project github page. You can also get an idea of how to use the library by looking at the main.lua file in the demo. Both the github page and the demo are linked on the first post of this thread.

For Advanced Tile Loader, I don't have any pointers, since I haven't used it.
When I write def I mean function.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: bump.lua - minimal collision detection lib

Post by Roland_Yonaba »

kikito wrote:For Advanced Tile Loader, I don't have any pointers, since I haven't used it.
Me too, but I AdvTile Loader has a wiki.
You may find some relevant resources there.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests