simple physics question

Just playing around with physics for the first time.

I don’t want to use a png image to represent a space ship, but rather, draw it using lines

So can someone explain why this spaceship doesn’t fall off the platform?

local physics = require "physics" physics.start() physics.setGravity( 0, 10 ) physics.setDrawMode("hybrid") local myRectangle = display.newRect(0, 600, 320, 100) myRectangle:setFillColor(140, 140, 140) myRectangle:setStrokeColor(180, 180, 180) physics.addBody( myRectangle, "static", { density=1.6, friction=0.5, bounce=0.1, shape=rectangleShape } ) local ship = display.newLine( 200,0, 300,200 ) ship:append( 200,160, 100,200, 200,0 ) ship.x = 310 ship.y = 0 shipRightShape = { 100,200, 0,160, 0,0} shipLeftShape = {-100,200, 0,160, 0,0} physics.addBody( ship, "dynamic", { density=1.6, friction=0.5, bounce=0.2, shape=shipRightShape }, { density=1.6, friction=0.5, bounce=0.2, shape=shipLeftShape } )

Think I’ve worked it out.

shipLeftShape vertices are anti-clockwise, when I believe they should only ever be clockwise

local physics = require "physics" physics.start() physics.setGravity( 0, 10 ) physics.setDrawMode("hybrid") local myRectangle = display.newRect(0, 600, 320, 100) myRectangle:setFillColor(140, 140, 140) myRectangle:setStrokeColor(180, 180, 180) physics.addBody( myRectangle, "static", { density=1.6, friction=0.5, bounce=0.1, shape=rectangleShape } ) local ship = display.newLine( 200,0, 300,200 ) ship:append( 200,160, 100,200, 200,0 ) ship.x = 350 ship.y = 0 shipRightShape = { 100,200, 0,160, 0,0} shipLeftShape = {0,160, -100,200, 0,0} physics.addBody( ship, "dynamic", { density=1.6, friction=0.5, bounce=0.2, shape=shipRightShape }, { density=1.6, friction=0.5, bounce=0.2, shape=shipLeftShape } )

Hello @dax trajero,

Yes, you’re correct. The vertices should be declared in clockwise order. Also, remember that you can’t have any concave bends in the shape. You’re probably not doing that here (I didn’t examine this actual shape), but just note that for future reference.

Take care,

Brent

Thank you Brent. I’ll be sure to remember that. Having great fun with physics and Coronalabs!

Think I’ve worked it out.

shipLeftShape vertices are anti-clockwise, when I believe they should only ever be clockwise

local physics = require "physics" physics.start() physics.setGravity( 0, 10 ) physics.setDrawMode("hybrid") local myRectangle = display.newRect(0, 600, 320, 100) myRectangle:setFillColor(140, 140, 140) myRectangle:setStrokeColor(180, 180, 180) physics.addBody( myRectangle, "static", { density=1.6, friction=0.5, bounce=0.1, shape=rectangleShape } ) local ship = display.newLine( 200,0, 300,200 ) ship:append( 200,160, 100,200, 200,0 ) ship.x = 350 ship.y = 0 shipRightShape = { 100,200, 0,160, 0,0} shipLeftShape = {0,160, -100,200, 0,0} physics.addBody( ship, "dynamic", { density=1.6, friction=0.5, bounce=0.2, shape=shipRightShape }, { density=1.6, friction=0.5, bounce=0.2, shape=shipLeftShape } )

Hello @dax trajero,

Yes, you’re correct. The vertices should be declared in clockwise order. Also, remember that you can’t have any concave bends in the shape. You’re probably not doing that here (I didn’t examine this actual shape), but just note that for future reference.

Take care,

Brent

Thank you Brent. I’ll be sure to remember that. Having great fun with physics and Coronalabs!