Hey guys, I just fixed a major performance bug by implementing collision filters. Fist pump! But now my multi-element physics bodies aren’t working as before: collisions are only firing for one of the two elements in the body. I.e. my projectile bodies collide with the shield (element 1) but pass right through the rest of the body without registering a hit. Do I need to define each element of the body as a separate category within the collision filter or something?
I’ve used PhysicsEditor to create the shape outlines, but defined the filters in code. The “tracers” file is what’s output by PhysicsEditor. The “swordsman” enemy has two elements, a shield and a body.
local creepCollisionFilter = { categoryBits = 2, maskBits = 5 } local scaleFactor = 0.25 local physicsData = (require("tracers")).physicsData(scaleFactor) local physicsParams = physicsData:get("swordsman") physicsParams.filter = creepCollisionFilter physics.addBody( creep, "kinematic", physicsParams)
Here’s the relevant snippet from PhysicsEditor. Note that I did not set the filter properties myself – I only want to use PhysicsEditor to trace the sprites, but it added the filters anyway. As far as I can tell I’m overwriting them, and all the single-element bodies in the game collide just fine.
["swordsman"] = { { pe\_fixture\_id = "shield", density = 2, friction = 0, bounce = 0, filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 }, shape = { 49, 22 , 49, 39 , 36, 79 , 24, 74 , 9, 58 , 1, 22 , 14, 2 } }, { pe\_fixture\_id = "body", density = 2, friction = 0, bounce = 0, filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 }, shape = { 57, 19 , 1, -4 , 47, -31 , 65, -9 } }, { pe\_fixture\_id = "body", density = 2, friction = 0, bounce = 0, filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 }, shape = { 1, -4 , -14, -35 , -13, -55 , 4, -69 , 30, -67 , 47, -31 } } }
I’ve also tried setting the filter manually in PE or in the output above, but the result is exactly the same. Thanks!