Ah, well, I actually tried using pivot joints originally, but it didn’t seem to work for me. I just gave it another try. It still breaks. Basically, when I start dragging the handle, the joints break and get pulled away by the force of gravity on the balloon.
Here’s some pictures of it happening:
Before drag (it’s behaving really elastically, but the connections are stable) - http://puu.sh/iEn6O/6c6a28a56d.jpg
After drag (it pulls apart completely) - http://puu.sh/iEn7L/17732ae663.jpg
What might I be doing wrong?
Attached is the code for creating the balloon & chain using pivot joints:
[lua]
local function make_balloon( x, y, lw, lh, c )
local prevs = {}
balloon = display.newImage(“red_balloon_small.png”)
physics.addBody(balloon, “dynamic”, {density=100, bounce=0, friction = 1})
balloon.x, balloon.y = x, y
balloon.dampingRatio = 1
balloon.isSensor = true
balloon.gravityScale = 0
local balloonTop = display.newRect( x, y - balloon.contentHeight/2, lw, lh )
physics.addBody(balloonTop, “dynamic”, {density=100, bounce=0, friction = 1})
balloonTop:setFillColor(0,0,0)
local linker = physics.newJoint(“pivot”, balloonTop, balloon, balloon.x, balloon.y - balloon.contentHeight/2)
balloonTop.gravityScale = 100
balloonTop.alpha = 0
--balloonTop.isSensor = true
local balloonBottom = display.newRect( x, y + balloon.contentHeight/2, lw, lh )
physics.addBody(balloonBottom, “dynamic”, {density=100, bounce=0, friction = 1})
balloonBottom:setFillColor(0,0,0)
local linker = physics.newJoint(“pivot”, balloonBottom, balloon, balloon.x, balloon.y + balloon.contentHeight/2)
balloonBottom.isSensor = true
balloonBottom.alpha = 0
--balloonBottom.gravityScale = 100
handle = display.newCircle(0,0,25)
handle:setFillColor(1,0.2,0.4)
physics.addBody(handle,“static”, {isSensor = true})
handle.gravityScale = 0
handle:addEventListener( “touch”, handleDrag )
prevs[0] = balloon
for i = 1, c do
local link = display.newRect( x, balloon.y + balloon.contentHeight/2+(i*(lh) + 2), lw, lh )
link:setFillColor(0,0,0)
link.alpha = 0
link.isSensor = true
physics.addBody( link, “dynamic”,{ density=100.0} )
link.dampingRatio = 1
link.gravityScale = 0
if i == 1 then
local linker = physics.newJoint(“pivot”, link, prevs[i-1], prevs[i-1].x, prevs[i-1].y + (link.y - prevs[i-1].y)/2 + balloon.contentHeight/2)
linker.dampingRatio = 0
linker.isLimitEnabled = true
linker:setRotationLimits( -45, 45 )
else
local linker = physics.newJoint(“pivot”, link, prevs[i-1], prevs[i-1].x, prevs[i-1].y + (link.y - prevs[i-1].y)/2)
linker.dampingRatio = 0
linker.isLimitEnabled = true
linker:setRotationLimits( -45, 45 )
end
prevs[i] = link
end
handle.x,handle.y = x, prevs[c].y + lh + handle.contentHeight/2
local linker = physics.newJoint(“pivot”, handle, prevs[c], x, prevs[c].y + (prevs[c].y - handle.y)/2)
linker.dampingRatio = 0
linker.isLimitEnabled = true
linker:setRotationLimits( -45, 45 )
end
make_balloon(w/2, h/4, 5, 5, 30)
[/lua]