Can't move group with bodies with breaking physics? (code attached)

Have I got this right here in that you can’t move a group with “display object that have physics bodies” without breaking physics?   

If you run this code you see the box which is in a group doesn’t collide at the right point?

If I wanted to create a ragdoll within a group, then position the ragdoll (i.e. the group) as a whole to the right location on the screen, then it wouldn’t crash at the right points?  Am I missing something here?

local physics = require("physics") -- Background local displayW, displayH = display.contentWidth, display.contentHeight background = display.newRect(0, 0, display.contentWidth, display.contentHeight) background.strokeWidth = 0 background:setFillColor(1,1,1) background.width, background.height = displayW, displayH&nbsp; background.x, background.y = displayW/2, displayH/2 -- Physics Setup physics.start() physics.setDrawMode( "hybrid" ) physics.setGravity(0, 9) physics.pause() -- Groud local ground = display.newRect( displayW/2, displayH\*3/4, displayW, 100 ) ground.strokeWidth = 3 ground:setFillColor( 0,0,0,0.2 ) ground:setStrokeColor( 1, 0, 0 ) physics.addBody( ground, "static", { friction=0.5, bounce=0.3 } ) -- Box local box = display.newRect( displayW\*1/3, 100, 100,100 ) box.strokeWidth = 10 box:setFillColor(0,0,0,0.2) box:setStrokeColor( 0, 1, 0 ) physics.addBody( box, "dynamic", { friction=0.5, bounce=0.3 } ) -- Box in Group local boxGroup = display.newGroup() local boxIG = display.newRect(boxGroup, displayW\*2/3, 150, 100,100 ) boxIG.strokeWidth = 10 boxIG:setFillColor(0,0,0,0.2) boxIG:setStrokeColor( 0,0,1 ) physics.addBody( boxIG, "dynamic", { friction=0.5, bounce=0.5 } ) boxGroup.y = 200 -- \<\<==== DON'T SEEM TO BE ABLE TO MOVE THE GROUP WITHOUT CAUSING PHYSICS ISSUE -- Start Physics After Pause timer.performWithDelay(2000,&nbsp; function(event) physics.start() end )

You can’t (iirc) have physics bodies in different groups, then move those groups around independently, thats a no no.

You can have physics bodies in different groups, then move the children around independently however.

Ps: even if you don’t insert an object into a group, it still gets added to the “stage” group (accessed via display.getCurrentStage() )

any suggestions re how to ragdoll (multiple bodies) and then position it/move it where you need to move it?   

Hi Greg,

If you’re attaching a series of objects via joints (rag doll), then I assume you’re positioning the elements relative to some other core element (i.e. you position the body or head, then place the arms and legs relative to that). How about just setting a variable for the “core” element and then setting everything off that? Then, when re-positioning it, you loop through the elements and use the same relative positioning calculations?

Brent

Hi Brent - I actually haven’t added the joints yet.  I was just thinking of creating the physics objects (parts of a ragdoll) within a group, and then positioning the group.  But from what I’m seeing you really have to not move the group afterwards, which I think implies you either have to (a) put in a group but not move the group, so get the positioning right up front - so perhaps no benefit of a group anyway?, or (b) not use a group to start with. 

Hi Greg,

I suppose you “can” use a group and move it, as long as you offset the entire object (all parts) in relation to how far you moved the group. But in effect, that’s the same thing as not moving the group but instead moving all of the objects within it. So, it’s really up to you how to approach it, but yes, you’ll have to maintain the same coordinate space somehow for proper collisions.

Brent

thanks Brent - had forgotten about this constraint so it threw me for a bit :slight_smile:

You can’t (iirc) have physics bodies in different groups, then move those groups around independently, thats a no no.

You can have physics bodies in different groups, then move the children around independently however.

Ps: even if you don’t insert an object into a group, it still gets added to the “stage” group (accessed via display.getCurrentStage() )

any suggestions re how to ragdoll (multiple bodies) and then position it/move it where you need to move it?   

Hi Greg,

If you’re attaching a series of objects via joints (rag doll), then I assume you’re positioning the elements relative to some other core element (i.e. you position the body or head, then place the arms and legs relative to that). How about just setting a variable for the “core” element and then setting everything off that? Then, when re-positioning it, you loop through the elements and use the same relative positioning calculations?

Brent

Hi Brent - I actually haven’t added the joints yet.  I was just thinking of creating the physics objects (parts of a ragdoll) within a group, and then positioning the group.  But from what I’m seeing you really have to not move the group afterwards, which I think implies you either have to (a) put in a group but not move the group, so get the positioning right up front - so perhaps no benefit of a group anyway?, or (b) not use a group to start with. 

Hi Greg,

I suppose you “can” use a group and move it, as long as you offset the entire object (all parts) in relation to how far you moved the group. But in effect, that’s the same thing as not moving the group but instead moving all of the objects within it. So, it’s really up to you how to approach it, but yes, you’ll have to maintain the same coordinate space somehow for proper collisions.

Brent

thanks Brent - had forgotten about this constraint so it threw me for a bit :slight_smile: