Help with wheel joints

Does anyone have any example code to demonstrate the use of the wheel joint? I've been trying to use it and it never seems to work as it is supposed to.

The below thread suggests that physics implementation in Corona is broken, I'm starting to think this is still the case...

(http://developer.anscamobile.com/forum/2010/10/30/pivot-joints-and-apparent-elasticity)

What I'm trying to do is implement something very similar to the second example in the link below, but it doesn't seem possible.

(http://www.emanueleferonato.com/2009/04/06/two-ways-to-make-box2d-cars/)

Thanks for any and all help!

Billy Cart does not use wheel joints, but thanks anyway!

I've previously looked carefully at Billy Cart and whilst it's very good, it shouldn't be that complicated and (no offense to the coder) it should be possible for it to be a lot better. If anything Billy Cart highlights the problems I've encountered.

Cheers again though.

Any news at all on this? Sorry to keep harping on about it but it's really frustrating!

What is it in the billy cart example doesn't work for you? I made a car in my game using pivot joints and I have no issues whatsoever. I didn't add suspension to the car like the billy cart example did, just a car with wheels and when needed I add force to make the car move. The car will also free-roll on a slope.

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!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- 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
views:1994 update:2011/10/10 21:27:38
corona forums © 2003-2011