The biggest thing I can see is that the piston joints should be constrained to one axis, but are not - this leads to the wheels moving horizontally.
This isn’t using piston joints, and I’m probably just being an idiot (it happens a lot!), but in the code below firstly the wheels should be centred on the welds, but are not.
Secondly the welds move significantly (I understand they are likely to have some ‘give’ but to me it seems too much to be correct).
Thirdly even if you change the weld positions so the wheels are centred on them (y value for front_weld and rear_weld = 30) the pivot joint does not ‘hold’ as it should.
I’ll be the happiest man alive if someone points out that I’m being stupid!
[lua]-- Start physics
local physics = require(“physics”)
physics.start()
physics.setGravity( 0 , 10 )
– Set physics drawmode
physics.setDrawMode( “hybrid” )
– Hide statusbar
display.setStatusBar( display.HiddenStatusBar )
–Determine Device Size
local disw = display.contentWidth
local dish = display.contentHeight
local car = display.newGroup()
–Create The Car
local car_body = display.newRect(0, 0, 102, 20)
car_body:setFillColor(100,75,75)
local rear_weld = display.newRect(14, 10, 8, 8)
local front_weld = display.newRect(84, 10, 8, 8)
rear_weld:setFillColor(100,50, 50)
front_weld:setFillColor(100, 50, 50)
local car_rear_wheel = display.newCircle( rear_weld.x, rear_weld.y, 15 )
local car_front_wheel = display.newCircle( front_weld.x, front_weld.y, 15 )
car_rear_wheel:setFillColor(25,128,25)
car_front_wheel:setFillColor(25,25,200)
–Add An Environment
local lwall = display.newRect(0, 0, 0,dish )
local rwall = display.newRect(disw,0,disw,dish)
local rshape = {0,0,disw,30}
local terrain = display.newRect (-80,200,500,50)
terrain.rotation = 10
local terrainBump = display.newRect (150,196,100,10)
terrainBump.rotation = -5
–Apply The Physics
physics.addBody(lwall,“static”, {friction=0.5})
physics.addBody(rwall,“static”, {friction=0.5})
physics.addBody(terrain, “static”, { density = 1.0, friction = 0.5, bounce = 0.1 })
physics.addBody(terrainBump, “static”, { density = 1.0, friction = 0.5, bounce = 0.1 })
physics.addBody(car_body,{density=0,friction=0,bounce=0})
physics.addBody(rear_weld,{density=0,friction=0,bounce=0})
physics.addBody(front_weld,{density=0,friction=0,bounce=0})
physics.addBody(car_rear_wheel,{density=2,friction=3,bounce=0,radius=15})
physics.addBody(car_front_wheel,{density=2,friction=3,bounce=0,radius=15})
– Create the Joints
local rear_weld_joint = physics.newJoint(“weld”, rear_weld, car_body, rear_weld.x, rear_weld.y)
local front_weld_joint = physics.newJoint(“weld”, car_body, front_weld, front_weld.x, front_weld.y)
local rear_wheel_joint = physics.newJoint(“pivot”,car_rear_wheel,rear_weld,rear_weld.x, rear_weld.y)
local front_wheel_joint = physics.newJoint(“pivot”,front_weld,car_front_wheel,front_weld.x, front_weld.y)
–Keep The Wheels Separated
local wheel_distance_joint = physics.newJoint(“distance”,car_rear_wheel, car_front_wheel, car_rear_wheel.x, car_rear_wheel.y, car_front_wheel.x, car_front_wheel.y)
–Populate The Scene
car:insert(lwall)
car:insert(rwall)
car:insert(floor)
car:insert(ramp)
car:insert(car_body)
car:insert(car_rear_wheel)
car:insert(car_front_wheel)
return car[/lua]
The above is a mashup of someone else’s code and some of mine purely for demonstration. Thanks for any and all advice! [import]uid: 74917 topic_id: 15110 reply_id: 56088[/import]