Irregular polygon and physics bodies misaligned

Hi I’ve just updated my app to G2.0 but I’m experiencing a fundamental issue with creating physics bodies from irregular polygons. The physics bodies are misaligned with the visible polygon when created using the same set of vertices. Is this related to auto-centering? Is there a work-around?

The following code snippet demonstrates the problem:

 local pshape = { -5,-10, 10,-10, 15,0, 10,10, -5,15 } local p = display.newPolygon( 160, 300, pshape ) p.fill = { 1, 0, 0 } physics.addBody( p, "static", { shape=pshape } )

When viewed in “hybrid” mode, you’ll see the physics body and visible polygon are misaligned.

Just wondering if I’m doing something wrong as it seems pretty fundamental? Any help would be appreciated. 

Hi Glenn,

Yes, this is a result of the auto-centering of physics bodies. It’s been filed as a potential issue to fix, but currently you’ll need to offset the physics body points based on the calculated center of the polygon.

Best regards,

Brent

Thanks Brent, I’ll give that a go.

Glenn

Hi Glenn,

Yes, this is a result of the auto-centering of physics bodies. It’s been filed as a potential issue to fix, but currently you’ll need to offset the physics body points based on the calculated center of the polygon.

Best regards,

Brent

Thanks Brent, I’ll give that a go.

Glenn