Collision between different groups

It seems like there is no collision detection between objects of different groups, is there any workaround for this problem?

I have  enemy groups contains  2 child objects that being continuously created at random times, and I want to detect the collision between those objects and the player which is in its own group. 

Are you leaving the groups at position <0,0>?  

Box 2D via Corona does not support collisions when objects are in separate groups and those groups have different offsets.

There is not workaround other than not to do that.

Ex:

-- THIS WILL WORK local group1 = display.newGroup() local group2 = display.newGroup local ball = display.newCircle( group1, 100, 100, 10 ) local block = display.newRect( group2, 100, 150, 30, 10 ) physics.addBody( ball ) physics.addBody( "static", block )

versus…

-- This WILL NOT WORK AS YOU MIGHT EXPECT local group1 = display.newGroup() local group2 = display.newGroup group2.x = 20 local ball = display.newCircle( group1, 100, 100, 10 ) local block = display.newRect( group2, 80, 150, 30, 10 ) physics.addBody( ball ) physics.addBody( "static", block )

The reason I’m creating enemy groups is that my enemy structure contains of different objects each with its own movement, and I want that entire enemy structure to move as a single unit, and that’s why I’m putting each structure in its own group because they are being randomly created. I think the alternative would be to add the object  to a table and at that to another table and loop through it in order to move them, but that might not be very practical. 

As long as you are not moving the groups, then putting the objects in different groups is NOT the problem.  The physics engine is unaware of groups.  

Check your collision code.  

Hi abdou, It is best to steer clear of moving “groups” when using the physics engine for collisions. As mentioned above the box2d engine is unaware and really silly things begin to happen. Best bet is to set your physics engine drawmode to hybrid and see what is happening, it will become self explanatory:https://docs.coronalabs.com/api/library/physics/setDrawMode.html. You can them re-evaluate your code.

Are you leaving the groups at position <0,0>?  

Box 2D via Corona does not support collisions when objects are in separate groups and those groups have different offsets.

There is not workaround other than not to do that.

Ex:

-- THIS WILL WORK local group1 = display.newGroup() local group2 = display.newGroup local ball = display.newCircle( group1, 100, 100, 10 ) local block = display.newRect( group2, 100, 150, 30, 10 ) physics.addBody( ball ) physics.addBody( "static", block )

versus…

-- This WILL NOT WORK AS YOU MIGHT EXPECT local group1 = display.newGroup() local group2 = display.newGroup group2.x = 20 local ball = display.newCircle( group1, 100, 100, 10 ) local block = display.newRect( group2, 80, 150, 30, 10 ) physics.addBody( ball ) physics.addBody( "static", block )

The reason I’m creating enemy groups is that my enemy structure contains of different objects each with its own movement, and I want that entire enemy structure to move as a single unit, and that’s why I’m putting each structure in its own group because they are being randomly created. I think the alternative would be to add the object  to a table and at that to another table and loop through it in order to move them, but that might not be very practical. 

As long as you are not moving the groups, then putting the objects in different groups is NOT the problem.  The physics engine is unaware of groups.  

Check your collision code.  

Hi abdou, It is best to steer clear of moving “groups” when using the physics engine for collisions. As mentioned above the box2d engine is unaware and really silly things begin to happen. Best bet is to set your physics engine drawmode to hybrid and see what is happening, it will become self explanatory:https://docs.coronalabs.com/api/library/physics/setDrawMode.html. You can them re-evaluate your code.