Joints keeps breaking

Hi there

I have two floating balloons attached with a rope. It’s a semple rope made with pivot joints.

However the joint keeps breaking once the rope collides with a static object and lets the balloons to escape. Please see the attached screenshot.

here is my code:

physics = require( “physics” )
physics.start()

local ropeParts = display.newGroup()
myBg = display.newImage( “bg.png”, 0, 0 )
myObj = display.newImage( “obj.png”, 200, 250 )
myObj2 = display.newImage( “obj.png”, 50, 250 )
obstacle = display.newImage( “obstacle.png”, 50, 100 )
hang = display.newImage( “hang.png”, 120, 270 )

physics.addBody( myObj, { density=2, friction=0.05, bounce=0.01 } )
physics.addBody( myObj2, { density=2, friction=0.05, bounce=0.01 } )
physics.addBody( obstacle, “static”, { friction=0.5, bounce=0.3 } )
physics.addBody( hang, “static”, { friction=0.5, bounce=0.3 } )

local board = {}
local joint = {}

for j = 1,10 do
    board[j] = display.newImage( “rope.png” )
    board[j].x = 200 - (j*10)
    board[j].y = 300
    physics.addBody(board[j])
    if(j == 1) then
        local joint = physics.newJoint(‘pivot’, myObj, board[j], board[j].x+9, board[j].y)
    end
    if(j > 1) then
        local joint = physics.newJoint(‘pivot’, board[j-1], board[j], board[j].x+9, board[j].y)
    end
    if(j == 10) then
                local joint = physics.newJoint(‘pivot’, myObj2, board[j], board[j].x-9, board[j].y)
    end
    
end

myObj.gravityScale = -.25
myObj2.gravityScale = -.25
 

Any suggesions to make the joints more rigid/solid. ??

Thank you!

The problem here is the age old “irresistible force vs immovable object” problem. This happens because you’re using a static object.

The solution I use is to have a single static object somewhere offscreen (eg: at 0,0) and make it a sensor (I call it my anchor.) Then any static object you currently have becomes dynamic but you add a weld joint between it and the anchor object.

This approach allows the Box2D physics engine to compute sensible values during collisions.

You can take a look here at my chains example:

http://springboardpillow.blogspot.co.uk/2012/04/sample-code.html?m=1

Code:
http://developer.coronalabs.com/code/chains

The problem here is the age old “irresistible force vs immovable object” problem. This happens because you’re using a static object.

The solution I use is to have a single static object somewhere offscreen (eg: at 0,0) and make it a sensor (I call it my anchor.) Then any static object you currently have becomes dynamic but you add a weld joint between it and the anchor object.

This approach allows the Box2D physics engine to compute sensible values during collisions.

You can take a look here at my chains example:

http://springboardpillow.blogspot.co.uk/2012/04/sample-code.html?m=1

Code:
http://developer.coronalabs.com/code/chains