Hi guys,
I have a fairly simple car physics simulation and I’m having issues with the wheels.
The wheels are attached to the box with a pivot joint and between the wheels there is a distance joint.
The car is moved only by gravity.
The problem (as you can see if you execute the code) is that the wheels have an erratic behavior when hitting the bump (there’s a bump on the level, just wait a few seconds) and when hitting the ground back. The wheels are moved outside the joint point and then they return.
I’ve been trying several fixes and combinations without any success.
display.setStatusBar( display.HiddenStatusBar )
require "physics"
physics.start()
physics.setDrawMode("hybrid")
physics.setScale(60)
local main = display.newGroup()
local level = display.newRect(-700, 1800, 10000, 500)
main:insert(level)
level:setFillColor(0, 0, 128)
level.rotation = 20
physics.addBody(level, "static", {density=1.5, bounce=0, friction=0.2})
bump = display.newRect(2800, 1300, 300, 300)
main:insert(bump)
bump:setFillColor(255, 255, 255)
bump.rotation = -15
physics.addBody(bump, "static", {density=1.5, bounce=0, friction=0.2})
local box = display.newRect(100, 75, 200, 50)
main:insert(box)
box:setFillColor(100,50, 50)
physics.addBody(box, {density=2, bounce=0.1, friction=0.2})
local frontWheel = display.newCircle(box.x + 45, box.y + 60, 30)
main:insert(frontWheel)
physics.addBody(frontWheel, {density=1.5, bounce=0.1, friction=0.1, radius=30})
local rearWheel = display.newCircle(box.x - 45, box.y + 60, 30)
main:insert(rearWheel)
physics.addBody(rearWheel, {density=1.5, bounce=0.1, friction=0.1, radius=30})
local frontPivot = physics.newJoint("pivot", frontWheel, box, frontWheel.x, frontWheel.y)
local rearPivot = physics.newJoint("pivot", rearWheel, box, rearWheel.x, rearWheel.y)
local dist = physics.newJoint("distance", frontWheel, rearWheel, frontWheel.x, frontWheel.y, rearWheel.x, rearWheel.y)
function update(event)
main.x = (box.x \* -1) + display.contentWidth / 2
main.y = (box.y \* -1) + display.contentHeight / 2
end
Runtime:addEventListener("enterFrame", update)
Any ideas?
Thanks in advance
[import]uid: 13694 topic_id: 16934 reply_id: 316934[/import]

[import]uid: 18554 topic_id: 16934 reply_id: 63637[/import]