Hi,
I am trying to write an engine that resembles that of all the hill racing games.
I just can’t get my bike to ride on the segments without it freaking out because of some imaginary bumps, even on a straight line. When a new segment begins, there seems to be an edge. No matter if it has the same height as that one before. I tried wheel joints, dampings, masses, frictions, etc etc… The bike feels like it was riding on a minefield. Why does this happen?
Thanks in advance!
local physics = require("physics") physics.start() physics.setScale(72) physics.setDrawMode("hybrid") physics.setContinuous = true display.setStatusBar(display.HiddenStatusBar) display.setDefault("background", 1,1,1) display.setDefault("fillColor", 0.7,0.7,0.7) local \_W = display.contentWidth local \_H = display.contentHeight local \_w = \_W/2 local \_h = \_H/2 local hasFriction = 1 local hasBounce = 0 local oLength = 20 local oCount = 150 ---- local world = display.newGroup() local obstacle = {} for a = 1,oCount do local theShape = {oLength/2,150, -oLength/2,150, -oLength/2,-150, oLength/2,-150} obstacle[a] = display.newPolygon(oLength\*(a-2), \_H, theShape) physics.addBody(obstacle[a], "static", {friction = hasFriction, shape = theShape, density = 100000, bounce = hasBounce}) obstacle[a].isBullet = true world: insert(obstacle[a]) end local bikeAt = {60,200} local bikeShape = {-8,-16, 24,-16, 24,16, -24,16} local bike = { display.newCircle(bikeAt[1]-20, bikeAt[2], 13), display.newCircle(bikeAt[1]+20, bikeAt[2], 13), display.newPolygon(bikeAt[1], bikeAt[2]-10, bikeShape) } physics.addBody(bike[1], "dynamic", {radius = 13, friction = hasFriction, density = 0.01, bounce = hasBounce}) physics.addBody(bike[2], "dynamic", {radius = 13, friction = hasFriction, density = 0.01, bounce = hasBounce}) physics.addBody(bike[3], "dynamic", {shape = bikeShape, friction = hasFriction, density = 0.01, bounce = hasBounce}) bike[1].isRiding = false for a = 1,3 do world: insert (bike[a]) end local wheel1joint = physics.newJoint("pivot", bike[1], bike[3], bike[1].x, bike[1].y) local wheel2joint = physics.newJoint("pivot", bike[2], bike[3], bike[2].x, bike[2].y) wheel1joint.isMotorEnabled = true wheel1joint.maxMotorTorque = 0.1 local timer = 0 local function onTouch(e) if e.phase == "began" then bike[1].isRiding = true wheel1joint.maxMotorTorque = 0.1 elseif e.phase == "ended" then timer = 0 bike[1].isRiding = false wheel1joint.motorSpeed = 0 wheel1joint.maxMotorTorque = 0.0003 end end Runtime: addEventListener ("touch", onTouch) local function moveBike() if bike[1].isRiding == true then timer = timer + 1 wheel1joint.motorSpeed = -700-timer\*30 end end Runtime: addEventListener("enterFrame", moveBike) local function camera() world.x = -bike[1].x+bikeAt[1] end Runtime: addEventListener("enterFrame", camera)