[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 »

Hi, definitively you will have to use filters for that. The way you use them will depend a bit on what you want to do with the collision information (or wether you want to have that information at all) and on how you can tell appart the player and the enemies from the environment (in my code I will assume that your items have a property called isEnvironment, isEnemy or isPlayer.

If you only want your player and enemies to collide with the environment, and "completely ignore" each other, you can simply make the filter function return "slide" for the environment and nil for everyting else in both cases:

Code: Select all

local filter = function(item, other)
  if other.isEnvironment then return 'slide' end -- replace '.isEnvironment' by whatever you use
end
Then you can pass that filter function as the last parameter of world:move of the player and enemies:

Code: Select all

local cols, len = world:move(player, targetX, targetY, filter)
...
local cols, len = world:move(enemy, targetX, targetY, filter)
If you have done everything correctly, the player and the enemies will ignore each other.

Another possibility is that you don't want them to completely ignore each other: you want them to "physically pass" through each other, but you want to know about their collision (for example to decrease the player health gradually, or to play a sound). In that case, the filter should return a "slide" collision for the environment, and a "cross" collision for the player/enemies.

Code: Select all

local playerFilter = function(item, other)
  if other.isEnvironment then return 'slide' end
  if other.isEnemy then return 'cross' end
end
...
local cols, len = world:move(player, targetX, targetY, playerFilter)
...
local enemyFilter = function(item, other)
  if other.isEnvironment then return 'slide' end
  if other.isPlayer then return 'cross' end
end
...
local cols, len = world:move(enemy, targetX, targetY, enemyFilter)
With this code the player and enemies will brehave like before (they will seem to ignore each other), but you will get an extra collision inside cols, to indicate that they are "traversing each other".
When I write def I mean function.
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

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

Post by Kasperelo »

Thank you :)
alexzhengyi
Prole
Posts: 5
Joined: Mon Oct 26, 2015 2:03 am

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

Post by alexzhengyi »

EDIT: to recall: My idea was adding 4 new "collision types". In addition of "slice", "cross", etc, you would have "◢", "◣", "◤" and "◥" (the unicode name is provisional). In theory, it's as simple as writing 4 new functions. In theory.[/quote]
Is it possible to add slope with any angle, not just that 45 degree.
alexzhengyi
Prole
Posts: 5
Joined: Mon Oct 26, 2015 2:03 am

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

Post by alexzhengyi »

any plane to add one way platform support?
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 »

They are already in.

Check the "platforms" branch:

https://github.com/kikito/bump.lua/tree/platforms
When I write def I mean function.
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 »

alexzhengyi wrote:Is it possible to add slope with any angle, not just that 45 degree.
Slopes are not supported for now. That conversation was theoretical only. When (if) I implement them, they won't be only 45-degrees.
alexzhengyi wrote:any plane to add one way platform support?
They are already in.

Check the "platforms" branch:

https://github.com/kikito/bump.lua/tree/platforms
When I write def I mean function.
alexzhengyi
Prole
Posts: 5
Joined: Mon Oct 26, 2015 2:03 am

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

Post by alexzhengyi »

Thanks
Sarcose
Prole
Posts: 48
Joined: Wed Jul 08, 2015 12:09 am

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

Post by Sarcose »

On that slope discussion earlier, wouldn't it be simplest from a "collision checks on the fly" perspective for the map to 'know' its surface vectors, and have character movement plot along them?

As in, in any of the examples earlier, the ground may be several dozen separate tiles with separate vectors, but the surface we're walking along can be described as a single line. As long as we're walking on the ground, we can only advance one or other direction along that exact directional path. Checking if we're falling off a ledge or not might get a bit complex, with this approach. I already use an isGrounded check using bump's world in my own project, but I only have strictly horizontal walkable surfaces so far.

(would a map generating knowledge of its own walkable segments at load-time be a good solution to this?)
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 »

Sarcose wrote:wouldn't it be simplest from a "collision checks on the fly" perspective for the map to 'know' its surface vectors, and have character movement plot along them?
I don't think so, but please send a pull request if you think you can implement that.
Sarcose wrote:the ground may be several dozen separate tiles with separate vectors, but the surface we're walking along can be described as a single line
Jasoco has done just that on his Mario game - in his case just to have less collisions. I think it is too specific to be included in bump (which is not a tile-only library).
Sarcose wrote:(would a map generating knowledge of its own walkable segments at load-time be a good solution to this?)
It would be ... possible, I guess. I don't know if it would be worth it or even a good idea. One of the benefits of bump is that it minimizes the amount of information you need from "the tiles around the current tile" in order to take decisions. A "map which knows collision stuff" goes in the opposite direction of that.
When I write def I mean function.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

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

Post by Jasoco »

I would love to have whatever collision detection and resolution library that allows for slopes and is easy to use. Even if I have to replace the library I'm currently using as long as it works. Bump is great but would be better with slopes. Even just simple ones. But I can get by without them for now while I develop the game. It would just be so much cooler if I had them now. Even if I have to implement a secondary collision system just for slopes.

Frankly, I'd love to have a library that let me do arbitrary shapes and let me create levels like in NSMB where you can have platforms that tilt or gears that are turning and collide with them correctly. But I ain't even about to try and figure out how to properly do that in Box2D. (Which I've never been able to get working at all or even understand how to use.)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests