I have this situation, The asteroids on the left. I don’t understand, why display object and physics body are misaligned?
v2014.2393
[lua]
local vertices={}
vertices= { -40.5, -88 , 79.5, -80 , 105.5, -18 , 62.5, 34 , -36.5, 66 , -94.5, -17 , -116.5, -86 }
local function A1()
local astX=math.random(-100,0)
local astY=math.random(0,display.contentHeight)
local asteroid=display.newPolygon(astX,astY,vertices)
asteroid:setFillColor( 0,0,0,0 )
asteroid.strokeWidth=5
asteroid:setStrokeColor( 1,1,1 )
physics.addBody( asteroid, “dynamic”, {density=500, friction=100, bounce=0, shape=vertices } )
local astVx=math.random(-50,50)
local astVy=math.random(-50,50)
asteroid:setLinearVelocity( astVx+50, astVy )
end
[/lua]
And I have not even changed the anchor point, although in the official documentation says:
If you change the anchorX or anchorY property of a display object before adding a physics body, the body will be positioned properly relative to the adjusted anchor. However, you should not change the anchor point after adding the body or the object and body will be misaligned.
Thus if I change the anchor of the display objects before addbody everthing should work, but they are misaligned with default anchor point or custom anchor point.
This happen in physics.setDrawMode(“hybrid”) as in physics.setDrawMode(“normal”).