Windmills and pendulums

duplicate post. see below [import]uid: 52127 topic_id: 9631 reply_id: 37041[/import]

ok, but I need a static object in this case. How do you create a spinning object without using an anchor?

physics.addBody( mill, "static", physicsData ); mill.fixture = physics.newJoint( "pivot", anchor, mill, 160, 200 ); -- What does this line need to look like if I'm not using an anchor? [import]uid: 52127 topic_id: 9631 reply_id: 37042[/import]

Look at lines 41,42 and 43 of my code above [import]uid: 8271 topic_id: 9631 reply_id: 37107[/import]

I’ve been asked for a working copy of my code posted above, as it appears to have got mangled at some point.

Here’s the dropbox link: https://dl.dropboxusercontent.com/u/10254959/Help/Pendulum/main.lua

Here’s the code:

-- WINDMILL local physics = require("physics") physics.start() physics.setDrawMode( "hybrid" ) -- normal, hybrid, debug local anchor = display.newCircle( 0,0,5 ) anchor.alpha = .1 physics.addBody( anchor, "static", { friction=0, bounce=0, density=0 } ) local hub = display.newCircle( display.contentCenterX, display.contentCenterY, 40 ) physics.addBody( hub, "dynamic", { friction=1, bounce=.1, density=3, radius=40 } ) hub.fixture = physics.newJoint( "pivot", anchor, hub, hub.x, hub.y ) local function tap( event ) local ball = display.newCircle( event.x, event.y, 20 ) physics.addBody( ball, "dynamic", { friction=1, bounce=.1, density=1, radius=20 } ) function ball:timer( event ) if (ball.y \> 1500) then timer.cancel( ball.t ) ball.t = nil ball:removeSelf() end end ball.t = timer.performWithDelay( 10000, ball, 3 ) end local function addarm( hub, rot ) arm = display.newRect( 0, 0, 20, 100 ) arm.x, arm.y = display.contentCenterX, display.contentCenterY - 80 physics.addBody( arm, "dynamic", { friction=1, bounce=.1, density=1 } ) arm.connect = physics.newJoint( "weld", hub, arm, hub.x, hub.y ) hub.rotation = hub.rotation + rot end for i=1, 4 do addarm( hub, 90 ) end hub.fixture.isMotorEnabled = true hub.fixture.motorSpeed = 20 hub.fixture.maxMotorTorque = 40 Runtime:addEventListener( "tap", tap ) -- PENDULUM pend = display.newRect( 0, 0, 10, 100 ) pend.x, pend.y = 100, display.contentCenterY physics.addBody( pend, "dynamic", { friction=1, bounce=.1, density=3 } ) pend.axis = physics.newJoint( "pivot", anchor, pend, pend.x, pend.y-pend.height/2 ) pend.axis.isMotorEnabled = true pend.axis.motorSpeed = 20 pend.axis.maxMotorTorque = 40 function pend:timer( event ) if (pend.rotation \> 50 or pend.rotation \< -50) then pend.axis.motorSpeed = 1 - pend.axis.motorSpeed end end pend.pulse = timer.performWithDelay( 500, pend, 0 )

I’ve been asked for a working copy of my code posted above, as it appears to have got mangled at some point.

Here’s the dropbox link: https://dl.dropboxusercontent.com/u/10254959/Help/Pendulum/main.lua

Here’s the code:

-- WINDMILL local physics = require("physics") physics.start() physics.setDrawMode( "hybrid" ) -- normal, hybrid, debug local anchor = display.newCircle( 0,0,5 ) anchor.alpha = .1 physics.addBody( anchor, "static", { friction=0, bounce=0, density=0 } ) local hub = display.newCircle( display.contentCenterX, display.contentCenterY, 40 ) physics.addBody( hub, "dynamic", { friction=1, bounce=.1, density=3, radius=40 } ) hub.fixture = physics.newJoint( "pivot", anchor, hub, hub.x, hub.y ) local function tap( event ) local ball = display.newCircle( event.x, event.y, 20 ) physics.addBody( ball, "dynamic", { friction=1, bounce=.1, density=1, radius=20 } ) function ball:timer( event ) if (ball.y \> 1500) then timer.cancel( ball.t ) ball.t = nil ball:removeSelf() end end ball.t = timer.performWithDelay( 10000, ball, 3 ) end local function addarm( hub, rot ) arm = display.newRect( 0, 0, 20, 100 ) arm.x, arm.y = display.contentCenterX, display.contentCenterY - 80 physics.addBody( arm, "dynamic", { friction=1, bounce=.1, density=1 } ) arm.connect = physics.newJoint( "weld", hub, arm, hub.x, hub.y ) hub.rotation = hub.rotation + rot end for i=1, 4 do addarm( hub, 90 ) end hub.fixture.isMotorEnabled = true hub.fixture.motorSpeed = 20 hub.fixture.maxMotorTorque = 40 Runtime:addEventListener( "tap", tap ) -- PENDULUM pend = display.newRect( 0, 0, 10, 100 ) pend.x, pend.y = 100, display.contentCenterY physics.addBody( pend, "dynamic", { friction=1, bounce=.1, density=3 } ) pend.axis = physics.newJoint( "pivot", anchor, pend, pend.x, pend.y-pend.height/2 ) pend.axis.isMotorEnabled = true pend.axis.motorSpeed = 20 pend.axis.maxMotorTorque = 40 function pend:timer( event ) if (pend.rotation \> 50 or pend.rotation \< -50) then pend.axis.motorSpeed = 1 - pend.axis.motorSpeed end end pend.pulse = timer.performWithDelay( 500, pend, 0 )