Smooth Hill Segments

Changing the shapes to rectangles makes no difference.

I’m the author of Level Director and one of my users came across a similar problem where it was snagging against joined objects/polygons.

Apart from creating a single polygon/rectangle that covers a large area the only way I could make it work smoothly was by using chain edge physics, so it might be worth taking a look.

FYI - http://forums.coronalabs.com/topic/55079-bezier-curves-physics-and-ghost-vertices/?hl=edge

The next version of Level Director will support chain edge physics for bezier curves and normal line paths (very useful for terrain style games).

Hope this helps.

Hi @philipp3,

The advice that @retrofitProductions provides is the same I was going to give you. For a hill racing game, you should use Box2D “edge shape” (chain) bodies instead of a series of polygons. Not only are they easier to work with for this purpose, but they allow for up to 32 segments, while shapes are limited to 8 segments.

Here is the official documentation on this topic:

http://docs.coronalabs.com/api/library/physics/addBody.html#edge-shape-chain-body

Brent

Thank you both! Never heard of that before, to be honest. I will try that out and tell if it worked :slight_smile:

Thank you so much, this works perfectly. Just why would anyone not want to use edge shape bodies?

Btw, when Brent said to change the density to 1, your response was that you changed the mass and it didn’t help. Did you change a value called mass, or the actual density value to 1? Just wondering, because if you did change it to ‘mass’ and the problem persisted, that’s why.

I see no reason why, for example, a ball rolling along a series of rectangle would bounce at all, given the above parameter.

Oh I meant density, not mass.

I just knocked this up to test the idea. Is this what you’re looking for?

require("physics") physics.start() physics.setGravity(0,10) physics.setDrawMode("hybrid") for i=1, 10 do local r = display.newRect( (display.actualContentWidth/10)\*(i-.5), display.actualContentHeight\*.75, display.actualContentWidth/10, display.actualContentHeight\*.5 ) r.fill = {0,1,0} physics.addBody( r, "static" ) end local body = display.newRect( display.actualContentWidth\*.15, display.actualContentHeight\*.35, 200, 100 ) body.fill = {1,0,0} local frontwheel = display.newCircle( body.x-75, body.y+50, 50 ) frontwheel.fill = {0,0,1} local backwheel = display.newCircle( body.x+75, body.y+50, 50 ) backwheel.fill = {0,0,1} physics.addBody( body, "dynamic", { friction=.2, bounce=.1, density=1 } ) physics.addBody( frontwheel, "dynamic", { friction=.2, bounce=.1, density=1, radius=50 } ) physics.addBody( backwheel, "dynamic", { friction=.2, bounce=.1, density=1, radius=50 } ) local frontaxle = physics.newJoint( "pivot", body, frontwheel, frontwheel.x, frontwheel.y ) local backaxle = physics.newJoint( "pivot", body, backwheel, backwheel.x, backwheel.y ) local function activateMotor( motor, speed ) motor.isMotorEnabled = true motor.motorSpeed = speed motor.maxMotorTorque = 100000 end timer.performWithDelay( 2000, function() activateMotor( frontaxle, 200 ) activateMotor( backaxle, 200 ) end, 1 )

Sorry, I know I’m late to this thread…

Hey horacebury,

Thanks a lot for your time. I modified your code a bit to show the problem (my vehicle will drive pretty fast). After a few elements, it will start to shake:

(Edge shape bodies work fine though)

require("physics") physics.start() physics.setGravity(0,20) --physics.setDrawMode("hybrid")     local gameGroup = display.newGroup() gameGroup: scale (0.3,0.3) gameGroup: translate (0,200)   for i=1, 100 do local r = display.newRect( (display.actualContentWidth/10)\*(i-1.5), display.actualContentHeight\*.75, display.actualContentWidth/10, display.actualContentHeight\*.5 ) r.fill = {0,1,0} physics.addBody(r, "static", {friction = 1, bounce = 0}) gameGroup: insert (r) end   local body = display.newRect( display.actualContentWidth\*.15, display.actualContentHeight\*.35, 200, 100 ) body.fill = {1,0,0} local frontwheel = display.newCircle( body.x-75, body.y+50, 50 ) frontwheel.fill = {0,0,1} local backwheel = display.newCircle( body.x+75, body.y+50, 50 ) backwheel.fill = {0,0,1}   physics.addBody( body, "dynamic", { friction=.2, bounce=.1, density=1 } ) physics.addBody( frontwheel, "dynamic", { friction=.2, bounce=.1, density=1, radius=50 } ) physics.addBody( backwheel, "dynamic", { friction=1, bounce=0, density=1, radius=50 } )   gameGroup: insert (body) gameGroup: insert (frontwheel) gameGroup: insert (backwheel)   local frontaxle = physics.newJoint( "pivot", body, frontwheel, frontwheel.x, frontwheel.y ) local backaxle = physics.newJoint( "pivot", body, backwheel, backwheel.x, backwheel.y )   local counter = 0 local function activateMotor( motor, speed ) motor.isMotorEnabled = true counter = counter + 1 motor.motorSpeed = speed motor.maxMotorTorque = 800 end   timer.performWithDelay( 1000, function() activateMotor( frontaxle, 10000000 ) --activateMotor( backaxle, 200 ) end, 1 )       local function camera() gameGroup.x = 100-body.x\*0.3 end Runtime: addEventListener("enterFrame", camera)