Physics wheels turning each other

I want to achieve the effect of wheels turning each other like gears.
I have created some wheels; circular physics bodies that have pivot joints to a static body. The wheels are positioned so they are touching. I apply isMotorEnabled true on one of them with a motorSpeed and it rotates as expected..
However I would expect the wheel that touches the motorised wheel to turn in the opposite direction but it doesn't. Now the bizarre thing is that if I create another non-jointed dynamic physics object and position it where the two wheels touch, it will fall away and leave the wheels turning and interacting as I would expect them to.
Can anyone shed any light on this for me? I want to achieve this affect without having to place obsolete bodies on every point a wheel contacts another.

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
local physics = require("physics")
physics.start()
 
local _W = display.contentWidth
local _H = display.contentHeight
 
--> Board
local board = display.newRect(0, 0, _W, _H)
board:setFillColor(140, 140, 140)
physics.addBody( board, "static", { friction=0.5, bounce=0.3 } )
 
--> Wheel 1
local wheel1 = display.newCircle( _W/2, _H/2, 50 )
wheel1:setFillColor(128,128,128)
physics.addBody( wheel1, { density=5, friction=5, bounce=0, radius=5 } )
wheel1Joint = physics.newJoint( "pivot", board, wheel1, wheel1.x, wheel1.y, 0, 0 )
wheel1Joint.isMotorEnabled = true
wheel1Joint.motorSpeed = 100
wheel1Joint.maxMotorTorque = 100000
 
--> Wheel 2
local wheel2 = display.newCircle( _W/2, _H/2+75, 25 )
wheel2:setFillColor(128,128,128)
physics.addBody( wheel2, { density=5, friction=5, bounce=0, radius=25 } )
wheel2Joint = physics.newJoint( "pivot", board, wheel2, wheel2.x, wheel2.y, 0, 0 )
 
--> Box --> Note: without the box the wheels don't interact, very strange
local box = display.newRect(_W/2-20, _H/2+50, 40, 40)
box:setFillColor(140, 140, 140)
physics.addBody( box, { density=5, friction=5, bounce=0} )

I very much want to get turning circular bodies interact with each other in this way. Please does anyone have a solution to this???

Ok I figured this out. You will see in the example I provided there are some ODD things with joints!

First, these 2 must match (don't ask why I don't understand it myself!

1
2
3
4
5
6
7
8
9
10
11
12
--Notice the -85, on the refpoint2?
 
local refpoint2 = display.newCircle (_W/2, _H/2 - 85, 5)
physics.addBody( refpoint2, "static")
refpoint2:setFillColor (255,0,0)
refpoint2.alpha = .1
ui:insert(refpoint2)
 
 
--notice the -85 on the myjoint2? 
 
local myJoint2 = physics.newJoint( "pivot", refpoint2, gears2, _W/2, _H/2 -85)
views:1546 update:2011/10/22 9:46:13
corona forums © 2003-2011