videos of Piston Joint in action

I’ve really been wrestling with how to use Piston Joint in Dr. Burton’s Corona SDK book.

Does anyone have a YouTube video of this in action or an app that use this and was created with Corona SDK?

I’d love to see one example just to see it in action.

I’m losing faith!!!

Yeah, that’s kind of what i thought.

With pivots, I’m also am having no luck with

.isLimitEnabled

:setRotationLimits

 

I just can’t seem to limit the movement of a hammer pic connected to a lever (display.newLine).  They just spin 360 degrees in a circle.

It can be really hard finding educational, real-world examples of these things.  

Hi @rshanlon,

Can you please post some simple code here, to show how you’re setting up your physics objects and joints?

Thanks,

Brent

This example is regarding the .isLimitEnabled and

:setRotationLimits

The hammer is in a 3 o’clock position ready to strike a gong.  The lever is in an 8 o clock position which should rotate the hammer to strike the gong.  A circle falls onto the lever triggering the whole thing.

[lua]

display.setStatusBar( display.HiddenStatusBar )

local physics = require(“physics”)

physics.start(true)

physics.setGravity(0, 9.8)

centerX = display.contentWidth/2

centerY = display.contentHeight/2

–SOUNDS

gong_sound = audio.loadSound( “sounds/Single_Gong.mp3” )

   gongs_sound = audio.loadSound( “sounds/ Gong.mp3” )

audio.setVolume( .3 )

–IMAGES

local bg = display.newRect( centerX, centerY, display.contentWidth, display.contentHeight )

local fastener = display.newCircle( display.contentWidth/2, -5, 25 )

fastener:setFillColor( 0,0,0 )

local gongRope = display.newImage( “images/rope.png”, centerX, centerY*.25 )

local gong = display.newImage( “images/Burmabell.png”, centerX, centerY-175)

local timerCircle = display.newCircle( centerX, centerY+100, 30 )

timerCircle:setFillColor( 1, 0, 0, .4 )

leverGroup = display.newGroup( )

local hammer = display.newImage( “images/hammer.png”, timerCircle.x+100, timerCircle.y-95 )

hammer.rotation = 45

leverGroup:insert( hammer)

local floor = display.newRect( 0, display.contentHeight, display.contentWidth*2, 10 )

floor:setFillColor( 0,0,0 )

local post = display.newRect( centerX-350, centerY+200, 40, 630 )

post:setFillColor( 1,0,0 )

local lever = display.newRect( timerCircle.x-150, timerCircle.y, 300, 20 )

lever:setFillColor (.8, .5, .3)

leverGroup:insert(lever)

local ball = display.newCircle( post.x+4.5, post.y-329, 35 )

ball:setFillColor (0, .5, 1)

local ticker = display.newRect( post.x-29, post.y+305, 65, 20 )

ticker:setFillColor (0, .5, 0)

–PHYSICS

physics.addBody( fastener, “static”)

physics.addBody( gongRope, “dynamic”, {density=.1, friction=0, bounce=.3 } )

physics.addBody( gong, “dynamic”, {density=.2, friction=.5, bounce=.8 } )

physics.addBody( hammer, “dynamic”, {density=.8, friction=.3, bounce=.8 })

physics.addBody( timerCircle, “static” )

physics.addBody( post, “static” )

physics.addBody( lever, “dynamic”, {density=.3, friction=.3, bounce=.5 })

physics.addBody( ball, “dynamic”, {density=1, friction=.3, bounce=3 })

physics.addBody( ticker, “static”)

physics.addBody( floor, “static”)

–JOINTS

local stringJoint = physics.newJoint( “pivot”, fastener, gongRope, fastener.x, fastener.y )

local gongJoint = physics.newJoint( “weld”, gongRope, gong, gongRope.x, gongRope.y)

local hammerJoint = physics.newJoint( “pivot”, timerCircle, hammer, timerCircle.x, timerCircle.y-85)

hammerJoint.isLimitedEnabled=true

hammerJoint:setRotationLimits(0,45)

local lev_Ham_Joint = physics.newJoint(“pivot”, timerCircle, lever, timerCircle.x, timerCircle.y-25 )

lev_Ham_Joint.isLimitedEnabled=true

lev_Ham_Joint:setRotationLimits(180,360)

– local lev_hammerJoint = physics.newJoint( “pivot”, hammer, lever,  timerCircle.x, timerCircle.y)

– lev_hammerJoint.isLimitedEnabled=true

– lev_hammerJoint:setRotationLimits(-180,180)

local function moveTicker()

transition.to(ticker, {time=10000, y=(ball.y-20) })

end

moveTicker()

local function playGong (event)

if event.phase == “began” then

audio.play(gong_sound)

print( “It gonged!” )

end

end

gong:addEventListener( “collision”, playGong )

physics.setDrawMode(“normal”)

[/lua]

Hi @rshanlon,

Hmmm… on second thought, better if you zip up the entire project so I can see the images too.

Brent

Thanks for taking a look, Brent.

You can download the zip from here: https://www.dropbox.com/s/teum53ixbnp1d17/assign2_Rube%20Goldberg%20MAchine.zip

What I’m trying to solve is why :setRotationLimits  doesn’t seem to limit the motion of the hammer and lever.  In clock coordinates, I’d like to the hammer to go no farther than 12 o’clock and 4 o clock and the lever about 10 o clock and 6 o clock.

When I kick up the bounce on the ball, you’ll see that both the hammer and lever can still spin around 360 degrees.  So I’m not getting how setRotationLimit is working or if it is even working.

Thanks for your help!

Hi @rshanlon,

You didn’t spell the property correctly. It’s “isLimitEnabled”, not “isLimitedEnabled”. In the future, please refer to the property names here:

http://docs.coronalabs.com/guide/physics/physicsJoints/index.html

Take care,

Brent

Ahh, that’s embarrassing.  I stared it at so many times in Dr. Burton’s book trying to figure out what I was doing wrong but…oh well.

Thanks for the help!   : )

Just to clarify, the two numbers (-45,45)  are from the starting position of the object.  So if my hammer starts at the 3 o’ clock position then that means its limit is 45 degree clockwise from that start position and -45 degrees counter-clockwise from that starting position.

I kept thinking it was all based on zero degrees always being at the center-top position like the number 12 on a clock.

Yeah, that’s kind of what i thought.

With pivots, I’m also am having no luck with

.isLimitEnabled

:setRotationLimits

 

I just can’t seem to limit the movement of a hammer pic connected to a lever (display.newLine).  They just spin 360 degrees in a circle.

It can be really hard finding educational, real-world examples of these things.  

Hi @rshanlon,

Can you please post some simple code here, to show how you’re setting up your physics objects and joints?

Thanks,

Brent

This example is regarding the .isLimitEnabled and

:setRotationLimits

The hammer is in a 3 o’clock position ready to strike a gong.  The lever is in an 8 o clock position which should rotate the hammer to strike the gong.  A circle falls onto the lever triggering the whole thing.

[lua]

display.setStatusBar( display.HiddenStatusBar )

local physics = require(“physics”)

physics.start(true)

physics.setGravity(0, 9.8)

centerX = display.contentWidth/2

centerY = display.contentHeight/2

–SOUNDS

gong_sound = audio.loadSound( “sounds/Single_Gong.mp3” )

   gongs_sound = audio.loadSound( “sounds/ Gong.mp3” )

audio.setVolume( .3 )

–IMAGES

local bg = display.newRect( centerX, centerY, display.contentWidth, display.contentHeight )

local fastener = display.newCircle( display.contentWidth/2, -5, 25 )

fastener:setFillColor( 0,0,0 )

local gongRope = display.newImage( “images/rope.png”, centerX, centerY*.25 )

local gong = display.newImage( “images/Burmabell.png”, centerX, centerY-175)

local timerCircle = display.newCircle( centerX, centerY+100, 30 )

timerCircle:setFillColor( 1, 0, 0, .4 )

leverGroup = display.newGroup( )

local hammer = display.newImage( “images/hammer.png”, timerCircle.x+100, timerCircle.y-95 )

hammer.rotation = 45

leverGroup:insert( hammer)

local floor = display.newRect( 0, display.contentHeight, display.contentWidth*2, 10 )

floor:setFillColor( 0,0,0 )

local post = display.newRect( centerX-350, centerY+200, 40, 630 )

post:setFillColor( 1,0,0 )

local lever = display.newRect( timerCircle.x-150, timerCircle.y, 300, 20 )

lever:setFillColor (.8, .5, .3)

leverGroup:insert(lever)

local ball = display.newCircle( post.x+4.5, post.y-329, 35 )

ball:setFillColor (0, .5, 1)

local ticker = display.newRect( post.x-29, post.y+305, 65, 20 )

ticker:setFillColor (0, .5, 0)

–PHYSICS

physics.addBody( fastener, “static”)

physics.addBody( gongRope, “dynamic”, {density=.1, friction=0, bounce=.3 } )

physics.addBody( gong, “dynamic”, {density=.2, friction=.5, bounce=.8 } )

physics.addBody( hammer, “dynamic”, {density=.8, friction=.3, bounce=.8 })

physics.addBody( timerCircle, “static” )

physics.addBody( post, “static” )

physics.addBody( lever, “dynamic”, {density=.3, friction=.3, bounce=.5 })

physics.addBody( ball, “dynamic”, {density=1, friction=.3, bounce=3 })

physics.addBody( ticker, “static”)

physics.addBody( floor, “static”)

–JOINTS

local stringJoint = physics.newJoint( “pivot”, fastener, gongRope, fastener.x, fastener.y )

local gongJoint = physics.newJoint( “weld”, gongRope, gong, gongRope.x, gongRope.y)

local hammerJoint = physics.newJoint( “pivot”, timerCircle, hammer, timerCircle.x, timerCircle.y-85)

hammerJoint.isLimitedEnabled=true

hammerJoint:setRotationLimits(0,45)

local lev_Ham_Joint = physics.newJoint(“pivot”, timerCircle, lever, timerCircle.x, timerCircle.y-25 )

lev_Ham_Joint.isLimitedEnabled=true

lev_Ham_Joint:setRotationLimits(180,360)

– local lev_hammerJoint = physics.newJoint( “pivot”, hammer, lever,  timerCircle.x, timerCircle.y)

– lev_hammerJoint.isLimitedEnabled=true

– lev_hammerJoint:setRotationLimits(-180,180)

local function moveTicker()

transition.to(ticker, {time=10000, y=(ball.y-20) })

end

moveTicker()

local function playGong (event)

if event.phase == “began” then

audio.play(gong_sound)

print( “It gonged!” )

end

end

gong:addEventListener( “collision”, playGong )

physics.setDrawMode(“normal”)

[/lua]

Hi @rshanlon,

Hmmm… on second thought, better if you zip up the entire project so I can see the images too.

Brent

Thanks for taking a look, Brent.

You can download the zip from here: https://www.dropbox.com/s/teum53ixbnp1d17/assign2_Rube%20Goldberg%20MAchine.zip

What I’m trying to solve is why :setRotationLimits  doesn’t seem to limit the motion of the hammer and lever.  In clock coordinates, I’d like to the hammer to go no farther than 12 o’clock and 4 o clock and the lever about 10 o clock and 6 o clock.

When I kick up the bounce on the ball, you’ll see that both the hammer and lever can still spin around 360 degrees.  So I’m not getting how setRotationLimit is working or if it is even working.

Thanks for your help!

Hi @rshanlon,

You didn’t spell the property correctly. It’s “isLimitEnabled”, not “isLimitedEnabled”. In the future, please refer to the property names here:

http://docs.coronalabs.com/guide/physics/physicsJoints/index.html

Take care,

Brent

Ahh, that’s embarrassing.  I stared it at so many times in Dr. Burton’s book trying to figure out what I was doing wrong but…oh well.

Thanks for the help!   : )

Just to clarify, the two numbers (-45,45)  are from the starting position of the object.  So if my hammer starts at the 3 o’ clock position then that means its limit is 45 degree clockwise from that start position and -45 degrees counter-clockwise from that starting position.

I kept thinking it was all based on zero degrees always being at the center-top position like the number 12 on a clock.