Physical bodies not considering translation of parent groups

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]

When working with physics bodies you need to have them all in the same group or else you get odd results. This is due to the physics engine expecting all the bodies to share the same coordinate space.

This is stated in the documentation…

http://developer.anscamobile.com/content/game-edition-box2d-physics-engine#physics.setDrawMode

Read the paragraph that starts off with “When working with Corona display groups and Box2D”

[import]uid: 13780 topic_id: 12765 reply_id: 46837[/import]

I don’t think this is a bug. If physics engine took group translations into account, it would make some other things impossible. For example, if you only wanted to translate camera (which is a group) you would automatically move all of its children to a new physical location. But instead, you only want them to move to a new graphical location on the screen, while in the physical world, their coordinates should stay the same. Hope that makes sense, somebody correct me if I’m wrong. [import]uid: 64979 topic_id: 12765 reply_id: 46838[/import]

Thank you for your answers. The main reason I complained was that the debug overlay of the “hybrid” mode was very misleading. I thought display groups act like a scenegraph where physic objects would inherit the position of their graph nodes and be placed at their origin. [import]uid: 63565 topic_id: 12765 reply_id: 47126[/import]

Pretty much spent and hour trying to figure out why the hybrid view showed a physics object but nothing would collide with it. I need to read more lol [import]uid: 8545 topic_id: 12765 reply_id: 57915[/import]