[library] bump.lua v3.1.4 - Collision Detection

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by kikito »

@Imaculata, The problem you are referring to ("one object moving so fast in a single frame that it goes completely through another") is called tunnelling.

Nixola got it wrong - bump detects and properly handles tunnelling. That is actually what took me the longest to implement. You almost definitively don't need to do the collision checks "in pieces".

I say almost because there is one exception: very fast objects can sometimes tunnel through other very fast objects. bump assumes that you are moving items one by one; when an item is moving (when you call world:move(item, ...)), the rest of the items "are static". So fast player vs scenery is ok. Fast player vs a normal moving enemy is ok. But fast player vs, say, a fast bullet (or fast bullets between each other) can sometimes still do tunnelling. I think the sacrifice is ok; it makes the code and the library interface simpler.

Appart from that exception, bump is so good at detecting tunnelling that some people often have the opposite problem: they want to "teleport" something from one place to the other and they don't know how to do that (answer: you call world:update instead of world:move)
When I write def I mean function.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by Nixola »

Oops, sorry Kikito! It apprars I didn't recall correctly ^^'
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Sarcose
Prole
Posts: 48
Joined: Wed Jul 08, 2015 12:09 am

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by Sarcose »

S0lll0s wrote:"col" refers to an entry in the "cols" table: (snip)
Ah, thanks for that clarification. I still stumble when it comes to lua tables but I think I'm starting to get the hang of it (they're awesome, I might add). Now looking further I can see that col.touch.x and col.touch.y can be compared with col.bounce.x and col.bounce.y to get my bounce direction. Time to google some geometry again.
User avatar
Imaculata
Party member
Posts: 102
Joined: Mon Aug 10, 2015 2:51 pm

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by Imaculata »

Thanks for the reply, and that is excellent news. I will be trying to implement Bump soon, and I'll let you know how that works out.
Sarcose
Prole
Posts: 48
Joined: Wed Jul 08, 2015 12:09 am

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by Sarcose »

kikito wrote:both options can work. either "1 world per slice" or "everything in one world, and filter by slice". the former will probably be slightly more efficient, but also probably more difficult to work with.

also, please use the following thread to talk about bump, this one is about a previous version:

viewtopic.php?f=5&t=79223
Blargh, sorry. I did that from mobile. What would be the efficiency of using multiple worlds, if I may ask? I might just go with filters, like S0ll0s suggested, if it's not too much of a save.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by kikito »

The savings in efficiency will be difficult to ponder. They would depend in how populated your "layers" were, and how often they are in the same x and y. The extreme case is: You have 10000 layers, each one with 1 single element, but all the elements "overlap" (they have the same x and y, but different z).

With 1 single world and filters, if you want to move one of those 10000 items, even if it remains in the same z layer, bump would have to iterate over the other 9999 items. Each iteration would be fast- probably just a call to the filter. But still, 9999 calls per item add up.

With one separate world per z layer, you would save yourself those 9999 calls, since each "world" only contains items with the same z. So the item we are trying to move is essentially "alone". But moving things along the z axis would be much more contrived.

But you have to remember that that's the worst-case scenario. If your game is going to be more sparsely populated, or if things don't occupy the same x and y quite often, you will probably be fine. My advise would be trying it with one world + filters first. If you experience performance problems, change to the multiple-world solution.
When I write def I mean function.
User avatar
TheMeq
Citizen
Posts: 56
Joined: Fri Sep 02, 2011 9:56 pm
Location: Nottingham, UK

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by TheMeq »

I got this error,

Code: Select all

bump.lua:600: Item Image added to the world twice. 
I know what this error means, but, my borders are all the same image, so how do I get around this? Here is my tilemap code:

Do I have to create an image for each individual box?

Code: Select all

for my = 0 ,22 do
		for mx = 0 , 39 do
			v = mapdata[my+1][mx+1]
			
			if v == 1 then
				lg.draw(tile,bf,mx*64,my*64)
			end
			if v == 2 then
				lg.draw(tile,pf,mx*64,my*64)
			end
			if v == 3 then
				lg.draw(tile,bw,mx*64,my*64)
				world:add(tile,mx*64,my*64,64,64)
			end
			if v == 4 then
				lg.draw(tile,pw,mx*64,my*64)
				world:add(tile,mx*64,my*64,64,64)
			end
		end
	end
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by bobbyjones »

You would create a table as the handle for the tile. Like for example

Code: Select all

local tiles = {}
tiles[1] = {id=1,x=10,y=10,width=100,height=100}

world:add(tiles[1], 10,10, 100,100)
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by kikito »

TheMeq wrote:I know what this error means, but, my borders are all the same image, so how do I get around this?
You are supposed to insert an item as the first parameter of world:add. An item is something which has the following properties (or has a correspondence with them): x,y,width and height.

Even if you are calling it "tile" in your code, the variable "tile" holds a reference to an image. Images are not ideal items because even if they have a width and height, they don't have a specific x or y - they are "chunks of memory representing graphical data", not "instances of tiles". They are related, the same way that a picture of someone is related to that someone. But not enough.

So you need some other thing to use as an item. As bobbyjones says, Lua tables are a great candidate. You can insert your x,y,width and height in them (plus other stuff, like the image), and then when a collision happens, you can get them back.

Code: Select all

local tiles = {}
local TILE_W, TILE_H = 64,64

function createTile(world, image, x, y)
  local tile = {image=image, x=x*TILE_W, y=y*TILE_H}
  tiles[#tiles+1] = tile
  world:add(tile, tile.x, tile.y, TILE_W, TILE_H)
end
...
for my = 0 ,22 do
    for mx = 0 , 39 do
       v = mapdata[my+1][mx+1]
         
       if v == 1 then
          lg.draw(tile,bf,mx*TILE_W,my*TILE_H)
       end
       if v == 2 then
           lg.draw(tile,pf,mx*TILE_W,my*TILE_H)
       end
       if v == 3 then
          lg.draw(tile,bw,mx*TILE_W,my*TILE_H)
          createTile(world, tile, mx, my)
       end
       if v == 4 then
          lg.draw(tile,pw,mx*64,my*64)
          createTile(world, tile, mx, my)
       end
    end
 end
When I write def I mean function.
User avatar
TheMeq
Citizen
Posts: 56
Joined: Fri Sep 02, 2011 9:56 pm
Location: Nottingham, UK

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by TheMeq »

Hi all, managed to get it working, I don't know if I'm doing something wrong though, as there is a huge performance issue when my player collides with one of the wall objects. If I walk across the floor, I get 58-60 FPS, but if I hit a wall, that drops to 24-30 FPS, and if I hit a corner, 6-9 FPS.

My laptop isn't one of the best if I'm honest, but I wouldn't of expected a performance hit as hard as this.

I've attached my love file. You can skip the intro screens with any key twice to take you into the game. Thanks
Attachments
BangBang.love
(170.87 KiB) Downloaded 117 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest