does anyone know to how do a Beam Balance using physics?
Are you trying to implement a lever like physics arrangement?
To re-word things. This involves ‘beam’ (as you say), a fulcrum, and forces on either end of the beam.
If we consider just the beam and fulcrum we need:
- Beam - Rectangle w/ dynamic body.
- Fulcrum anchor - A rectangle or circle with a “static” body. Can have visible set to false and be made into a sensor to stop collision-response. This give a place that can’t move to mount our fulcrum and then the beam
- Fulcrum - A ‘pivot’ jointmounting the beam to the fulcrum anchor( can be offset )
thanks Edward.
When I get a chance I’ll put a sample in the SSK Sampler:
- https://github.com/roaminggamer/SSKCorona
- https://forums.coronalabs.com/topic/56979-ssk-update-may-22-2015/
Note: Monday’s a very busy day for me so this won’t happen till later today.
Thanks very much!
I’ll publish this in the SSK sampler tomorrow the 26th, but till then here is a video:
https://www.youtube.com/watch?v=Q5wwLZndJHU&feature=youtu.be
, and here is the SSK version of the code:
function public.run( group ) public.isRunning = true local physics = require("physics") physics.start() physics.setGravity(0,9.8) physics.setDrawMode( "hybrid" ) -- Localizations local newCircle = ssk.display.newCircle local newRect = ssk.display.newRect local newImageRect = ssk.display.newImageRect local easyIFC = ssk.easyIFC local mRand = math.random -- Locals -- -- A 'floor' -- newRect( group, centerX, bottom - 10, { w = 260, h = 20, fill = \_G\_, alpha = 0.5}, { bodyType = "static" } ) -- A fulcrum -- local fulcrum = newCircle( group, centerX, bottom - 60, { radius = 10, fill = \_Y\_, alpha = 0.5}, { bodyType = "static" } ) -- A beam (the lever) -- local beam = newRect( group, centerX, bottom - 80, { w = 200, h = 20, fill = \_C\_, alpha = 0.5}, { bodyType = "dynamic", friction = 1 } ) -- The Pivot -- local pivotJoint = physics.newJoint( "pivot", beam, fulcrum, fulcrum.x, fulcrum.y ) pivotJoint.isLimitEnabled = true pivotJoint:setRotationLimits( -10, 10 ) -- Drop a 'box' on the beam -- newRect( group, centerX + 60, bottom - 120, { size = 40, fill = \_R\_, alpha = 0.5}, { bodyType = "dynamic", friction = 1 } ) -- Over time, drop smaller boxes on the other side -- local function onTimer() if( not public.isRunning ) then return end local tmp = newRect( group, centerX - mRand(60, 90), bottom - 160, { size = 20, fill = \_O\_, alpha = 0.5}, { bodyType = "dynamic", friction = 0.5 } ) tmp.timer = display.remove timer.performWithDelay( 8000, tmp ) timer.performWithDelay( 1500, onTimer ) end timer.performWithDelay( 1500, onTimer ) end
Thanks again!
Are you trying to implement a lever like physics arrangement?
To re-word things. This involves ‘beam’ (as you say), a fulcrum, and forces on either end of the beam.
If we consider just the beam and fulcrum we need:
- Beam - Rectangle w/ dynamic body.
- Fulcrum anchor - A rectangle or circle with a “static” body. Can have visible set to false and be made into a sensor to stop collision-response. This give a place that can’t move to mount our fulcrum and then the beam
- Fulcrum - A ‘pivot’ jointmounting the beam to the fulcrum anchor( can be offset )
thanks Edward.
When I get a chance I’ll put a sample in the SSK Sampler:
- https://github.com/roaminggamer/SSKCorona
- https://forums.coronalabs.com/topic/56979-ssk-update-may-22-2015/
Note: Monday’s a very busy day for me so this won’t happen till later today.
Thanks very much!
I’ll publish this in the SSK sampler tomorrow the 26th, but till then here is a video:
https://www.youtube.com/watch?v=Q5wwLZndJHU&feature=youtu.be
, and here is the SSK version of the code:
function public.run( group ) public.isRunning = true local physics = require("physics") physics.start() physics.setGravity(0,9.8) physics.setDrawMode( "hybrid" ) -- Localizations local newCircle = ssk.display.newCircle local newRect = ssk.display.newRect local newImageRect = ssk.display.newImageRect local easyIFC = ssk.easyIFC local mRand = math.random -- Locals -- -- A 'floor' -- newRect( group, centerX, bottom - 10, { w = 260, h = 20, fill = \_G\_, alpha = 0.5}, { bodyType = "static" } ) -- A fulcrum -- local fulcrum = newCircle( group, centerX, bottom - 60, { radius = 10, fill = \_Y\_, alpha = 0.5}, { bodyType = "static" } ) -- A beam (the lever) -- local beam = newRect( group, centerX, bottom - 80, { w = 200, h = 20, fill = \_C\_, alpha = 0.5}, { bodyType = "dynamic", friction = 1 } ) -- The Pivot -- local pivotJoint = physics.newJoint( "pivot", beam, fulcrum, fulcrum.x, fulcrum.y ) pivotJoint.isLimitEnabled = true pivotJoint:setRotationLimits( -10, 10 ) -- Drop a 'box' on the beam -- newRect( group, centerX + 60, bottom - 120, { size = 40, fill = \_R\_, alpha = 0.5}, { bodyType = "dynamic", friction = 1 } ) -- Over time, drop smaller boxes on the other side -- local function onTimer() if( not public.isRunning ) then return end local tmp = newRect( group, centerX - mRand(60, 90), bottom - 160, { size = 20, fill = \_O\_, alpha = 0.5}, { bodyType = "dynamic", friction = 0.5 } ) tmp.timer = display.remove timer.performWithDelay( 8000, tmp ) timer.performWithDelay( 1500, onTimer ) end timer.performWithDelay( 1500, onTimer ) end
Thanks again!