Moving group of phyics objects

Thanks for the help

@vonncc123 You can move the display group with physics objects in it but you will need to move all the other display groups with physics objects in them as well.  Don’t use transition, use hard coordinates but you can use an enterFrame function to simulate transitions.

[lua]

Runtime:addEventListener( ‘enterFrame’, yourFunctionToMoveGroups )

[/lua]

Let us know if you have any hard code you would like us to take a look at.

local rect = display.newRect(\_W/2,\_H/2,50,50) physics.addBody(rect) rect.bodyType = "dynamic" local rect2 = display.newRect(\_W/2,\_H/2 + 70,50,50) physics.addBody(rect2) rect2.bodyType = "static" group:insert(rect) local function moveMe() group.x = group.x + 1 end

Here is my code, the group is still not falling, the object is moving to the right, but it still doesn’t fall.

What are you trying to achieve?

Based on your code, all you do is create two objects, one dynamic, one static, and place the dynamic object in the group. Then you just move the group to the right. So, what’s wrong?

Yup, exactly what you said, but the moving group’s objects are not falling, they’re just moving to the right. (Assume that the group has may objects), when I do it 1 by 1, the moving objects are falling, but when I do it as a group, they don’t fall

What I’m trying to achieve is that, the Group will fall as one.

My suggestion don’t move the group.  

I know it would be nice, but this simply won’t work the way you want it to with with physics bodies.

You need move the objects individually and keep all your groups aligned, otherwise your physics bodies will misbehave.

To @roaminggamer’s point, as far as I’ve understood, you can move a group with physics objects in it, but you need to be careful about it. The physics simulations will run correctly since all objects in the said group will be offset by the same amount. However, having multiple groups with physics objects in them will likely run into issues.

Taking your sample code and adding the necessary bits there, i.e.
 

local physics = require("physics") physics.setDrawMode( "hybrid" ) physics.start() local group = display.newGroup() local rect = display.newRect( 130, 100, 50, 50 ) physics.addBody( rect ) group:insert( rect ) local rect2 = display.newRect( rect.x+60, 100, 50, 50 ) physics.addBody( rect2, "static" ) group:insert( rect2 ) local function moveMe() group.x = group.x + 1 end Runtime:addEventListener( 'enterFrame', moveMe )

does result in the dynamic object(s) falling, as they should, and every display object on the screen moves right as per moveMe function.

If you want for the group to fall, then you’d have to move the group down (if I am understanding you correctly). If you are having problems with not all objects falling, then that’s due to one of them being a static object, which does not react to gravity.

That’s very unfortunate, Thanks for the answers though, had to do it manually. Had to manually move the x and y axis of everything, but the scaling will be as a group