I’ve been struggling with this bug for the last few hours till I finally found it. It seems like physical bodies don’t consider the translation of a parent group. Here’s some sample code:
local physics = require("physics");
physics.start();
physics.setGravity(0, 0)
physics.setDrawMode("hybrid");
--------------------------------------------------------------------------------
-- Print info of colliding objects.
local function onCollision(event)
local target = event.target;
local tParent = target.parent;
local other = event.other;
local oParent = other.parent;
print("Collision");
print("Target (parent): ", tParent.name, tParent.x, tParent.y, "Target:", target.x, target.y);
print("Other (parent): ", oParent.name, oParent.x, oParent.y, "Other:", other.x, other.y);
end
--------------------------------------------------------------------------------
-- Print names of colliding objects.
local function addBody(g)
local shapeRadius = 15;
-- create body shape and insert into group
local shape = display.newCircle(0, 0, shapeRadius);
g:insert(shape);
physics.addBody(shape, {isSensor=true, radius=shapeRadius});
shape:addEventListener("collision", onCollision);
end
--------------------------------------------------------------------------------
local function main()
-- create group A
local groupA = display.newGroup();
groupA.name = "group A";
groupA.x = 300; groupA.y = 100;
addBody(groupA);
-- create group B
local groupB = display.newGroup();
groupB.name = "group B";
groupB.x = 200; groupB.y = 200;
addBody(groupB);
end
main();
It seem like internally physics thinks both are at (0,0) while their visual representation and even their debug overlay is at (300,100) and (200,200). It’s a major flaw for us…please help. [import]uid: 63565 topic_id: 12765 reply_id: 312765[/import]