joint[#joint + 1] = physics.newJoint( "pivot", link[7], emptybucket, 200, 495 )

Hello, I am seeking a solution for a problem linking objects with joints. In debug mode, it looks like I have my 7 link rope all connected to “empty bucket”, but there seems to be a ton of space between " link[7] " and “emptybucket”. Can someone please help me close the gap so my rope looks taught?

Kind Regards, Jamie

HERE IS MY CODE:

–floor–
local rect = display.newRect( 0, 610, 1024, 600 )
rect:setFillColor( 255, 255, 255, 0 )
physics.addBody( rect, “static”, { density = 1.0, friction = 0.1, bounce = 0.2 } )

–links–
local link2 = display.newImage(“link.png”, 270, 340)
physics.addBody( link2, “static”, { density = 1.0, friction = 0.1 } )

local emptybucket = display.newImage(“emptybucket.png”, 150, 495)
physics.addBody( emptybucket, { density = 3.0, friction = .3, bounce = 0.2 } )

local link = {}
local joint = {}

for j = 1,7 do
link[j] = display.newImage( “link.png” )
link[j].x = 274
link[j].y = 340 + (j*25)

physics.addBody( link[j], {density=1, friction=0.1, bounce=0.2 } )

– create joints between links
if (j > 1) then
prevLink = link[j-1] – each link is joined with the one before it
else
prevLink = link2 – first board is joined to well
end

joint[j] = physics.newJoint( “pivot”, prevLink, link[j], 270, 340 + (j*25) )

end
– join final link to emptybucket
joint[#joint + 1] = physics.newJoint( “pivot”, link[7], emptybucket, 200, 495 )
[import]uid: 10840 topic_id: 30977 reply_id: 330977[/import]

Here’s a great rope demo:
http://developer.coronalabs.com/code/rope-demo [import]uid: 147322 topic_id: 30977 reply_id: 123938[/import]

Thank you very much for your response and lead. I found that demonstration very helpful. My problem is the connection “joint[#joint + 1]” to the final object, a bucket. Debug shows that there is a connection there, but I just can’t get the end of the rope to visibly connect to the top of the bucket. Right now the rope hangs down straight bc of the huge gap in joint, link.

I’ve gone through Bridges and Chains samples too… just can’t figure it out.

Does this make sense to anyone? Your thoughts are appreciated!

Jamie [import]uid: 10840 topic_id: 30977 reply_id: 123991[/import]

Hi Jamie,

If you could post a screenshot of what you are seeing in debug mode, that might be helpful.

Just glancing at your code, I notice that the links are all created with an x of 270 (then changed to 274), while the bucket has an x of 150, and the final joint an x of 200. Is this intentional? I don’t know what your images look like, so maybe it’s intentional, but I would have thought that if you wanted to start with a chain hanging straight down with a bucket at the end, the links, bucket, and joints would all start with the same x.

  • Andrew [import]uid: 109711 topic_id: 30977 reply_id: 124012[/import]

Here’s a great rope demo:
http://developer.coronalabs.com/code/rope-demo [import]uid: 147322 topic_id: 30977 reply_id: 123938[/import]

Thank you very much for your response and lead. I found that demonstration very helpful. My problem is the connection “joint[#joint + 1]” to the final object, a bucket. Debug shows that there is a connection there, but I just can’t get the end of the rope to visibly connect to the top of the bucket. Right now the rope hangs down straight bc of the huge gap in joint, link.

I’ve gone through Bridges and Chains samples too… just can’t figure it out.

Does this make sense to anyone? Your thoughts are appreciated!

Jamie [import]uid: 10840 topic_id: 30977 reply_id: 123991[/import]

Hi Jamie,

If you could post a screenshot of what you are seeing in debug mode, that might be helpful.

Just glancing at your code, I notice that the links are all created with an x of 270 (then changed to 274), while the bucket has an x of 150, and the final joint an x of 200. Is this intentional? I don’t know what your images look like, so maybe it’s intentional, but I would have thought that if you wanted to start with a chain hanging straight down with a bucket at the end, the links, bucket, and joints would all start with the same x.

  • Andrew [import]uid: 109711 topic_id: 30977 reply_id: 124012[/import]