This is actually a lot more trivial than it may seem.
First and foremost, make sure that the shape of your physics body is using relative coordinates from its own centre, i.e. for a 20 by 20 pixels rect, make it {-10,-10,10,-10,10,10,-10,10} and not, for instance {0,0,20,0,20,20,0,20}. There are plenty of simple functions that can do this for you as well.
Now, horizontally or vertically flipping a shape like that is as simple as changing the sign in front of the x or y vertices, i.e. turn positive x/y vertices into negative and vice versa.
Here’s the simplest function I could think of for accomplishing it:
local physics = require("physics") physics.start() physics.setDrawMode( "hybrid" ) local function flip( vertices, direction ) local t, v, h = {}, 1, 1 if direction == "v" then -- "v" for "vertical" v = -1 elseif direction == "h" then -- "h" for "horizontal" h = -1 else -- flip both v, h = -1, -1 end for i = 1, #vertices, 2 do t[i] = vertices[i]\*h t[i+1] = vertices[i+1]\*v end return t end local verticesOriginal = { -70, -40, 20, -60, 70, 60 } local verticesHorizontalFlip = flip( verticesOriginal, "h" ) local verticesVerticalFlip = flip( verticesOriginal, "v" ) local verticesBothFlip = flip( verticesOriginal ) local polygon1 = display.newPolygon( display.contentCenterX-100, display.contentCenterY-100, verticesOriginal ) physics.addBody( polygon1, "static", {shape=verticesOriginal} ) local polygon2 = display.newPolygon( display.contentCenterX+100, display.contentCenterY-100, verticesHorizontalFlip ) physics.addBody( polygon2, "static", {shape=verticesHorizontalFlip} ) local polygon3 = display.newPolygon( display.contentCenterX-100, display.contentCenterY+100, verticesVerticalFlip ) physics.addBody( polygon3, "static", {shape=verticesVerticalFlip} ) local polygon4 = display.newPolygon( display.contentCenterX+100, display.contentCenterY+100, verticesBothFlip ) physics.addBody( polygon4, "static", {shape=verticesBothFlip} )
Not convoluted at all, right?
Now, if you want to update the shapes after they’ve already been created, then simply remove the body and recreate it afterwards with the flipped vertices.