I’m trying to create an octagonal shape, starting with its upper left corner of its bounding rectangle at 120, 120, with a corresponding physics body. The polyline and physics body appear to be the right shape, but not aligned on the same space. Why?
The octagon is bounded by a 50x50 rectangle, with 30px sides.
The docs say that the coords of the physics shape are relative to the display object, which has its origin at the center of the display object by default. But in this code, it looks like the physics object is using the first point of the line as its center, and the poly line isn’t where I’d expect it either.
What am I doing wrong?
[lua]local physics = require( “physics” )
physics.start()
display.setStatusBar (display.HiddenStatusBar)
physics.setDrawMode( “hybrid” )
square1 = display.newRect( 60, 180, 60, 60)
physics.addBody( square1, “static”, { density=3.0, friction=0.5, bounce=0.2 } )
square2 = display.newRect( 120, 180, 60, 60)
physics.addBody( square2, “static”, { density=3.0, friction=0.5, bounce=0.2 } )
square3 = display.newRect( 180, 180, 60, 60)
physics.addBody( square3, “static”, { density=3.0, friction=0.5, bounce=0.2 } )
xStart = 120
yStart = 120
local octaShape = display.newLine( xStart+10, yStart, xStart+40, yStart )
octaShape:append( xStart+50, yStart+10, xStart+50, yStart+40, xStart+40, yStart+50, xStart+10, yStart+50, xStart, yStart+40, xStart, yStart+10, xStart+10, yStart )
octaShape:setColor( 255, 102, 102, 255 )
octaShape.width = 3
octaPhysicsBody = { -15, -25, 15, -25, 25, -15, 25, 15, 15, 25, -15, 25, -25, 15, -25, -15 }
physics.addBody( octaShape, { density=1.5, friction=0.5, bounce=0.2, shape=octaPhysicsBody } )[/lua] [import]uid: 82378 topic_id: 20519 reply_id: 320519[/import]
[import]uid: 52491 topic_id: 20519 reply_id: 80554[/import]
[import]uid: 52491 topic_id: 20519 reply_id: 80776[/import]