[FIXED] Collision Filters Not Working

Collision filters don’t seem to be working with Graphics 2.0, this is a big issue when making a game. Any idea when this may be working again?

Collision filters are working with my test apps.

One thing though: At the moment, Physics doesn’t take an object’s anchor point into consideration.

In physics “hybrid” mode it looks like all objects are in the correct location after setting the anchor point, but they’re still in the default (0.5,0.5) location with regards to collision events.

That is still a pretty big issue to not be working and may be the reason my game and my collision samples aren’t working. Any idea when Physics will take an object’s anchor point into consideration again?

@JoshuaNovak919, first off, reference points are not the same as anchor points.

Now in the 1.0 engine, Box2D ignored the reference point because Box2D does a real physical simulation, and therefore uses the center of mass.

In the 2.0 engine, Box2D imposes the same sort of limitations, so the point of rotation will be in the object’s center of mass. So the anchor point similarly gets ignored.

Hmm i’m not 100% sure what you mean. I do know it isn’t working at all for me. My game i had working with the previous graphics engine doesn’t work now, the enemies fall through the ground and the balloons demo let the balloons go through the walls etc. I’ll rebuild the balloon demo again and post it.

Ok i have the collision filter sample ready. I basically just added anchor points to the walls and color so you can see them. Is there a place i can send it/post it? If you run it with the newest daily build of Graphics 2.0 the balloons bounce and then just fall off the screen. I have the same issue in my game with enemies falling through objects they shouldn’t etc.

I filed a bug report (Case 27433) earlier today showing the issue.

@walter

This is a regression issue as Physics does respect reference points in G1.0 (at least when talking about the positioning of static objects). I’ve used it many times in apps developed with G1.0. 

In G2.0 hybrid mode, the objects seem to be in the correct location when setting anchor points, but the actual object with regards to collisions isn’t.

I’ve filed a bug report as indicated above.

Below you’ll find some code (bouncing ball) that has been modified to run with *both* G1.0 and G2.0 to show the issue. 

(In G2.0 the ball bounces off a wall that’s not there).

-- -- main.lua -- local physics = require("physics"); physics.start(); physics.setGravity(0, 0); physics.setDrawMode("hybrid"); local coronaBuild = system.getInfo("build"); local coronaVersion = tonumber(coronaBuild:sub(coronaBuild:find("%.")+1)); -- event handler local onEvent = function(event) print("onEvent",event.phase) end -- display some lines local fromX = display.contentCenterX; local fromY = 0; local toX = 0; local toY = display.contentHeight; local lineTable = {}; for i = 1, 240 do lineTable[i] = display.newLine(fromX, fromY, toX+(i\*2), toY); lineTable[i].strokeWidth = 1; end -- create walls local wall1 = display.newRect(0, 0, 20, display.contentHeight); if (coronaVersion \>2000) then wall1.anchorX, wall1.anchorY = 1, 0; else wall1:setReferencePoint(display.TopRightReferencePoint); end wall1.x, wall1.y = display.contentWidth-10, display.contentCenterY; physics.addBody(wall1, "static", {friction=0.0, bounce=1.0}); wall1.alpha = 0.2; wall1.isSensor = false; wall1:addEventListener("collision", onEvent); local wall2 = display.newRect(0, 0, 20, display.contentHeight); if (coronaVersion \> 2000) then wall2.anchorX, wall2.anchorY = 0, 1; else wall2:setReferencePoint(display.BottomLeftReferencePoint); end wall2.x, wall2.y = 10, display.contentCenterY; physics.addBody(wall2, "static", {friction=0.0, bounce=1.0}); wall2.alpha = 0.2; wall2.isSensor = false; wall2:addEventListener("collision", onEvent); -- create moving objects local ball = display.newCircle(display.contentCenterX, display.contentCenterY+50, 20); ball:setFillColor(0.6); physics.addBody(ball, "dynamic", {radius=20}); local ball2 = display.newCircle(display.contentCenterX, display.contentCenterY-50, 20); ball2:setFillColor(0.6); physics.addBody(ball2, "dynamic", {radius=20}); -- set in motion ball:setLinearVelocity(250, 0); ball2:setLinearVelocity(-250, 0);  

This issue has been fixed in build 2034.

Awesome!! Works perfect now. Thanks!

Yup, just the one caveat you should be aware of. From the checkin comment in build 2034: 

“you cannot change the anchor point after the addBody call.”

Yeah i noticed that. That is something i can work around for now.

Collision filters are working with my test apps.

One thing though: At the moment, Physics doesn’t take an object’s anchor point into consideration.

In physics “hybrid” mode it looks like all objects are in the correct location after setting the anchor point, but they’re still in the default (0.5,0.5) location with regards to collision events.

That is still a pretty big issue to not be working and may be the reason my game and my collision samples aren’t working. Any idea when Physics will take an object’s anchor point into consideration again?

@JoshuaNovak919, first off, reference points are not the same as anchor points.

Now in the 1.0 engine, Box2D ignored the reference point because Box2D does a real physical simulation, and therefore uses the center of mass.

In the 2.0 engine, Box2D imposes the same sort of limitations, so the point of rotation will be in the object’s center of mass. So the anchor point similarly gets ignored.

Hmm i’m not 100% sure what you mean. I do know it isn’t working at all for me. My game i had working with the previous graphics engine doesn’t work now, the enemies fall through the ground and the balloons demo let the balloons go through the walls etc. I’ll rebuild the balloon demo again and post it.

Ok i have the collision filter sample ready. I basically just added anchor points to the walls and color so you can see them. Is there a place i can send it/post it? If you run it with the newest daily build of Graphics 2.0 the balloons bounce and then just fall off the screen. I have the same issue in my game with enemies falling through objects they shouldn’t etc.

I filed a bug report (Case 27433) earlier today showing the issue.

@walter

This is a regression issue as Physics does respect reference points in G1.0 (at least when talking about the positioning of static objects). I’ve used it many times in apps developed with G1.0. 

In G2.0 hybrid mode, the objects seem to be in the correct location when setting anchor points, but the actual object with regards to collisions isn’t.

I’ve filed a bug report as indicated above.

Below you’ll find some code (bouncing ball) that has been modified to run with *both* G1.0 and G2.0 to show the issue. 

(In G2.0 the ball bounces off a wall that’s not there).

-- -- main.lua -- local physics = require("physics"); physics.start(); physics.setGravity(0, 0); physics.setDrawMode("hybrid"); local coronaBuild = system.getInfo("build"); local coronaVersion = tonumber(coronaBuild:sub(coronaBuild:find("%.")+1)); -- event handler local onEvent = function(event) print("onEvent",event.phase) end -- display some lines local fromX = display.contentCenterX; local fromY = 0; local toX = 0; local toY = display.contentHeight; local lineTable = {}; for i = 1, 240 do lineTable[i] = display.newLine(fromX, fromY, toX+(i\*2), toY); lineTable[i].strokeWidth = 1; end -- create walls local wall1 = display.newRect(0, 0, 20, display.contentHeight); if (coronaVersion \>2000) then wall1.anchorX, wall1.anchorY = 1, 0; else wall1:setReferencePoint(display.TopRightReferencePoint); end wall1.x, wall1.y = display.contentWidth-10, display.contentCenterY; physics.addBody(wall1, "static", {friction=0.0, bounce=1.0}); wall1.alpha = 0.2; wall1.isSensor = false; wall1:addEventListener("collision", onEvent); local wall2 = display.newRect(0, 0, 20, display.contentHeight); if (coronaVersion \> 2000) then wall2.anchorX, wall2.anchorY = 0, 1; else wall2:setReferencePoint(display.BottomLeftReferencePoint); end wall2.x, wall2.y = 10, display.contentCenterY; physics.addBody(wall2, "static", {friction=0.0, bounce=1.0}); wall2.alpha = 0.2; wall2.isSensor = false; wall2:addEventListener("collision", onEvent); -- create moving objects local ball = display.newCircle(display.contentCenterX, display.contentCenterY+50, 20); ball:setFillColor(0.6); physics.addBody(ball, "dynamic", {radius=20}); local ball2 = display.newCircle(display.contentCenterX, display.contentCenterY-50, 20); ball2:setFillColor(0.6); physics.addBody(ball2, "dynamic", {radius=20}); -- set in motion ball:setLinearVelocity(250, 0); ball2:setLinearVelocity(-250, 0);  

This issue has been fixed in build 2034.