Hello everyone,
The code was written in my early stages of learning Lua and Corona and so no finishing will be observed apologies for any inconvenience
What I have done is when touch happens, the object starts revolving around a fixed point and when released it starts moving in direction where the object is released.
The code was written in my early stages of learning Lua and Corona so not finishing will be observed
local physics = require( "physics" ) physics.start() physics.setDrawMode( "hybrid" ) physics.setGravity(0,0) -- r1=rotator, r2=rotator , b1=ball bg=display.newImage("Sky.png") bg:scale(1,2) vw=display.viewableContentWidth vh=display.viewableContentHeight r1=display.newImage("rotator.png",170,100) r1:scale(0.12,0.12) r2=display.newImage("rotator.png",380,200) r2:scale(0.12,0.12) b1 = display.newImage( "ab.png",100,200) b1:scale(0.031,0.031) physics.addBody( r1,"static",{radius=9}) physics.addBody( b1,"kinematics",{radius=9} ) physics.addBody( r2,"static",{radius=9}) b1:applyForce( 0.5, 0, b1.x, b1.y ) function tap( event ) if ( "began" == event.phase ) then transition.cancel( b1 ) if(r1.x\>b1.x and r1.y\<b1.y) then d1=((r1.x-b1.x)^2+(r1.y-b1.y)^2)^0.5 ms=100 else d1=((b1.x-r1.x)^2+(b1.y-r1.y)^2)^0.5 ms=-100 end if(r2.x\>b1.x and r2.y\<b1.y) then d2=((r2.x-b1.x)^2+(r2.y-b1.y)^2)^0.5 ms=100 else d2=((b1.x-r2.x)^2+(b1.y-r2.y)^2)^0.5 ms=-100 end if(d1\<d2) then myJoint = physics.newJoint( "pivot", r1,b1, r1.x, r1.y ) myJoint.isMotorEnabled = true myJoint.motorSpeed = ms myJoint.maxMotorTorque = 10000 myJoint.lineardamping=1 else myJoint = physics.newJoint( "pivot", r2,b1,r2.x, r2.y ) myJoint.isMotorEnabled = true myJoint.motorSpeed = ms myJoint.maxMotorTorque = 10000 myJoint.lineardamping=1 end elseif("ended"==event.phase) then display.remove(myJoint) end end bg:addEventListener("touch",tap)
I have done it successfully but when initially revolving starts it give glitches.
Please see if you all intelligent brains can help me by any means.
Every advices,opinions and help is welcome.
Thanks in advance.