Physics and groups

Hi!
I’ve noticed that physics objects in a group are no longer working once the container group is moved.
Actually, the group is moved, but the physics engine react to the original position of the physic body, not to its new position.
Is that normal? Is there a solution?

[code]display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR

–> Enable physics
local physics = require “physics”
physics.start()
–physics.setDrawMode( “debug” )
physics.setGravity( 0, 30 )

myRect = display.newRect( 100, 200, 100, 100 )
physics.addBody( myRect, “static”, { friction = 0.3 } )

myGroup = display.newGroup()
–physics.addBody( myGroup, “static”, { friction = 0.3 } ) --> Possible solution? Not working with or without this line anyway.

myGroup:insert( myRect )

myBall = display.newCircle( 100, 150, 30 )
myBall:setFillColor( 0, 0, 255 )
physics.addBody( myBall, “dynamic”, { density=1.2, friction=1, bounce=0.2 } )

myGroup.y = 200 --> when this line is removed, it’s working[/code]
[import]uid: 25327 topic_id: 7825 reply_id: 307825[/import]

Hi! I am also facing a similar issue when I try to rotate the display group. Any luck on your side? [import]uid: 33862 topic_id: 7825 reply_id: 29137[/import]

Hi,

I’ve read an article in this website saying that it is not recommended to use physics body in different groups as the may not interact with each other.

When working with Corona display groups and Box2D, it is important to keep in mind that Box2D expects all physics objects to share a global coordinate system. This means that a set of ungrouped Corona objects will work well, and a set of objects that are all added to the same display group should also work, since they will share the internal coordinates of that group – this is demonstrated in the “EggBreaker” sample code, which uses a single moving display group to create a “moving camera” effect.
However, unexpected results may occur if physical objects are added to different display groups, especially if the groups are then moved in different directions. The “hybrid” draw mode makes these issues much easier to diagnose, since it lets you overlay the physics engine’s collision boxes and shapes on top of the Corona renderer.
Source : http://developer.anscamobile.com/content/game-edition-box2d-physics-engine

The best way to transform a group of physics bodies is to use the complex body contruction :

[lua]local car = display.newImage(“big_red_car.png”)
roofShape = { -20,-10, 20,-10, 20,10, -20,10 }
hoodShape = { 0,-35, 37,30, -37,30 }
trunkShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }

physics.addBody( car, “dynamic”,
{ density=3.0, friction=0.5, bounce=0.2, shape=roofShape },
{ density=6.0, friction=0.6, bounce=0.4, shape=hoodShape },
{ density=4.0, friction=0.5, bounce=0.4, shape=trunkShape }
)[/lua]

Source : http://developer.anscamobile.com/content/game-edition-physics-bodies

This exemple shows how to add 3 physics bodies to 1 display object wich you can transform as you want.

I hope this will help you :slight_smile: [import]uid: 25327 topic_id: 7825 reply_id: 29148[/import]

Hi Michael, unfortunately, the physic bodies added to the group are user-triggered. So, I am unable to use the piece of code which you attached. FYI, I am using only 1 display group but to no avail.

Thanks anyway. I will update you if I manage to get a workaround :slight_smile: [import]uid: 33862 topic_id: 7825 reply_id: 29337[/import]

I face the problem that my character’s arms collide with his legs and I dont want that, however, I want the arms and legs to collide with any other object. So I wanted to separate them in groups.
I thought about putting arms in group1, legs in group2 and then group1 and group2 in group3.
So
arms : dynamic
legs : dynamic
group1 : kinematic
group2 : kinematic
so that group1 and group2 do not collide
group3 : dynamic
so that group3 collides with the rest

But it doesnt work

Pls help! [import]uid: 41639 topic_id: 7825 reply_id: 38634[/import]

@fdt,

You should keep them in same display group, just use collision filters.

Here’s an excellent post on collision filter… ask if you need more help…
http://developer.anscamobile.com/forum/2010/10/25/collision-filters-helper-chart [import]uid: 48521 topic_id: 7825 reply_id: 38887[/import]