Page 14 of 23

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

Posted: Fri Oct 23, 2015 9:28 pm
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".

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

Posted: Sun Oct 25, 2015 2:18 pm
by Kasperelo
Thank you :)

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

Posted: Mon Oct 26, 2015 2:26 am
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.

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

Posted: Mon Oct 26, 2015 2:28 am
by alexzhengyi
any plane to add one way platform support?

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

Posted: Mon Oct 26, 2015 7:38 am
by kikito
They are already in.

Check the "platforms" branch:

https://github.com/kikito/bump.lua/tree/platforms

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

Posted: Mon Oct 26, 2015 9:06 am
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

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

Posted: Mon Oct 26, 2015 9:29 am
by alexzhengyi
Thanks

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

Posted: Mon Nov 02, 2015 10:26 pm
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?)

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

Posted: Tue Nov 03, 2015 1:05 am
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.

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

Posted: Tue Nov 03, 2015 3:51 am
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.)