Box2D is unlikely to merge such thing, because it already has at least three mechanisms in place to decide whether two shapes will collide.
LÖVE is unlikely to merge such thing, because maintaining the locally modified Box2D in sync with upstream is already painful enough, and having to merge more custom patches probably involves more work than the developers are willing to spend when they want to update the physics engine. Plus, it supports the three mechanisms I mention above.
But you can try. I'm not a LÖVE developer.
If you want to make it as simple as in your Unity example, you can try to find a LÖVE library that implements that function, or write one yourself. I wouldn't have much trouble writing one. EDIT Done, see below.
For your stated purpose, you could easily do it with groups: just set your player and your bullets to group -1. If you want the enemies to shoot and not collide with their own bullets, you can set the enemies and their bullets to group -2. That will prevent the enemies from colliding with each other, though, which may or may not be desirable. If you still want enemies to collide with each other, you probably have to start using categories instead.
EDIT: Here's a small library to implement a function to ignore pairs of fixtures.
Note it's untested. EDIT2: Tested now, fixed an issue.
Code: Select all
--[=======================================================================[--
Simple library to implement a function that allows causing two given fixtures
to not collide which each other.
Usage:
local world = love.physics.newWorld(...)
local ignoreCollision = require('stopCollision')(world)
...
ignoreCollision(fixture1, fixture2, true) -- add pair to ignore list
ignoreCollision(fixture1, fixture2, false) -- remove pair from ignore list
Written by Pedro Gimeno, donated to the public domain.
--]=======================================================================]--
local weak = {__mode = 'k'}
return function(world)
local collisionPairs = setmetatable({}, weak)
world:setContactFilter(function (fixt1, fixt2)
return not (collisionPairs[fixt1] and collisionPairs[fixt1][fixt2]
or collisionPairs[fixt2] and collisionPairs[fixt2][fixt1])
end)
return function(fixt1, fixt2, ignore)
if ignore then
-- Try to not duplicate pairs
if collisionPairs[fixt1] and collisionPairs[fixt1][fixt2] then return end
if collisionPairs[fixt2] then
collisionPairs[fixt2][fixt1] = true
return
end
if not collisionPairs[fixt1] then
collisionPairs[fixt1] = setmetatable({}, weak)
end
collisionPairs[fixt1][fixt2] = true
return
end
-- ignore is false - remove the entry
if collisionPairs[fixt1] then
collisionPairs[fixt1][fixt2] = nil
end
if collisionPairs[fixt2] then
collisionPairs[fixt2][fixt1] = nil
end
end
end
Note that if you want to have more than one physics world, you need to have one ignoreCollision function per world, otherwise it won't find the fixtures.