Bizarre rotation effect

The code below can be easily modified to have only one plank in the rotating seesaw group, ie: no group, just the seesaw.

Can anyone tell me why, when the group of two images is used, that the seesaw group starts rotating on its own and doesn’t stop. However, when a single image is used, anchored at the same place the group is, there is no rotation at all, unless something collides with it…?

Btw, I’ve referenced images found in the Collision samples.

local physics = require( “physics” )
physics.start()

local seesaw = display.newImage( “board.png” )
seesaw.x = display.contentWidth / 2 - 80
seesaw.y = display.contentHeight - 150
local seesaw2 = display.newImage( “board.png” )
seesaw2.x = display.contentWidth / 2 + 80
seesaw2.y = display.contentHeight - 150
local group = display.newGroup()
group:insert( seesaw ) – assume rect1 is an existing display object
group:insert( seesaw2 ) – assume rect2 is an existing display object

for i = 1, group.numChildren do
local child = group[i]
local description = (child.isVisible and “visible”) or “not visible”
print( “child[”…i…"] is " … description )
end

local anchor = display.newImage( “rock.png” )
anchor.x = display.contentWidth / 2
anchor.y = display.contentHeight - 150
anchor.myName = “anchor”
physics.addBody( anchor, “static”, { density=1.0, friction=0.5, bounce=0.0 } )

local body = physics.addBody( group, { density=1.0, friction=0.5, bounce=0.0 } )
local myJoint = physics.newJoint( “pivot”, anchor, group, anchor.x, anchor.y )
[import]uid: 8271 topic_id: 2033 reply_id: 302033[/import]

In general, a group of display objects will have a different reference point than a single display object.

With a single object, the reference point will default to the center, so if you are adding objects to a group and then turning the group into a physics body, it’s a good idea to “zero out” the internal object coordinates in the group by setting x=0, y=0. After that, it’ll probably behave more like the original object again.

Also, try turning on physics.setDrawMode( “hybrid” ) and see where Box2D thinks your objects are. Recall that Box2D assumes a single global coordinate system, so introducing display groups can also introduce coordinate offsets that it can’t know about. (If so, the usual fix is to again zero out the x,y of the objects inside the group after they are added to the group.) [import]uid: 3007 topic_id: 2033 reply_id: 6420[/import]