Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

GearJoint
Started by ashutoshpanda840 Jun 26 2019 06:13 AM

3 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ashutoshpanda840

[GLOBAL: userInfoPane.html]
ashutoshpanda840
  • Observer

  • 14 posts
  • Corona SDK

local physics=require("physics")
physics.start()
physics.setDrawMode( "hybrid" )
physics.setGravity(0,8)

local w=display.contentWidth
local h=display.contentHeight


local gearL=display.newCircle(w/2-30,h/2,30)
gearL:setFillColor(1,0,0,0.7)
physics.addBody(gearL,"dynamic",{radius=30,friction=0.5})

local gearR=display.newCircle(w/2+60,h/2,60)
gearR:setFillColor(1,0,0,0.7)
physics.addBody(gearR,"dynamic",{radius=60,friction=0.5})

local box=display.newRect(w/2+15,h/2,110,30)
box:setFillColor(0,1,0,0.3)
physics.addBody(box,"static")

local pivotJoint1=physics.newJoint("pivot",gearL,box,gearL.x,gearL.y)
local pivotJoint2=physics.newJoint("pivot",gearR,box,gearR.x,gearR.y)
local gearJoint1=physics.newJoint("gear",gearL,gearR,pivotJoint1,pivotJoint2,3.0)

pivotJoint1.isMotorEnabled=true
pivotJoint1.motorSpeed=30
pivotJoint1.maxMotorTorque=10000

Now let me tell the problem ,I want ask that if the joint is called a gear Joint than when one gear rotates the should automatically,but that doesn't happen when I compile the above code can some please explain gear Joint with small sample example because the corona documention is not enough( actually,I didn't get it!!!)

and also run the above code you will find that gearL is rotating but gearR is not but friction is present between them. 



[TOPIC: post.html]
#2

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,120 posts
  • Corona SDK

You have your pivots wrong....  try this

local pivotJoint1=physics.newJoint("pivot",box,gearL,gearL.x,gearL.y)
local pivotJoint2=physics.newJoint("pivot",box,gearR,gearR.x,gearR.y)

Also, there are some physics samples you can see in the simulator.


  • sporkfin likes this

[TOPIC: post.html]
#3

ashutoshpanda840

[GLOBAL: userInfoPane.html]
ashutoshpanda840
  • Observer

  • 14 posts
  • Corona SDK

Thanks I didn't notice that minute detail.



[TOPIC: post.html]
#4

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,366 posts
  • Corona SDK

for pivot joints, i think it helps to imagine that the first body contains the "motor", while the second body is attached to the "shaft".  so you had the gear driving the fixed box, instead of the fixed box driving the gear.  (as per SGS' already-correct answer)

 

if you had briefly set the box as dynamic (and disabled gravity so the whole contraption wouldn't fall off screen) it might have clued you in to the "where-is-the-motor-mounted" problem.  (because your box would then "counter-torque")  direction of rotation (ie, implied sign of motorSpeed) might have also seemed "backwards" to what you expected with reversed joint order.

 

it might also be instructive to consider how you'd do something similar without a gear joint.   imagine a rubber wheel driving another rubber wheel, allowing some slippage (use friction to control), instead of rigid gear teeth, and held together tightly with an external bar.   your code might look something like:

local physics=require("physics")
physics.start()
physics.setDrawMode( "hybrid" )
physics.setGravity(0,0) -- no gravity

local w=display.contentWidth
local h=display.contentHeight

local gearL=display.newCircle(w/2-30,h/2,30)
gearL:setFillColor(1,0,0,0.7)
physics.addBody(gearL,"dynamic",{radius=30,friction=0.5,density=2}) -- more density (to allow small gear to dominate)

local gearR=display.newCircle(w/2+60,h/2,60)
gearR:setFillColor(1,0,0,0.7)
physics.addBody(gearR,"dynamic",{radius=60.1,friction=10}) -- more radius (to ensure contact), more friction (to transfer rotation)

local box=display.newRect(w/2+15,h/2,130,30)
box:setFillColor(0,1,0,0.3)
physics.addBody(box,"dynamic") -- dynamic

local pivotJoint1=physics.newJoint("pivot",gearL,box,gearL.x,gearL.y) -- gear drives box
local pivotJoint2=physics.newJoint("pivot",box,gearR,gearR.x,gearR.y) -- box drives gear (tho doesn't matter, motor not used)

pivotJoint1.isMotorEnabled=true
pivotJoint1.motorSpeed=30
pivotJoint1.maxMotorTorque=10000

once you understand that setup you should be good-to-go with pivot joints.  then you're ready to add gear joints to them if/where needed.  (iow, get the pivot joints right before you worry about gear joints)  hth

 

[edit:  code fell out of code box on posting, fixed]


  • sporkfin likes this


[topic_controls]
[/topic_controls]