My chains have pivot joint with the notch in its side, i also wanna make chains joint to the ball so ball can pull chains to itself and it will look realistic, this is the state in “hybrid” mode;
It doesn’t matter if i choose the ball’s x and y for the pivot joint for chain-ball connection, i tried most coordinates but chains are still not sticking to the ball. What would you do to make this joint ? Something different than pivot ?
local ball = display.newImageRect("img/ball.png", 40, 40)
ball.x = 385
ball.y = 170
physics.addBody(ball, "dynamic", {density=2, friction=0.5,bounce=0.4,radius=20})
local notchl = display.newImageRect("img/notch.png", 40, 40)
notchl.x = 260
notchl.y = 70
physics.addBody(notchl, "static")
local notchr = display.newImageRect("img/notch.png", 40, 40)
notchr.x = 510
notchr.y = 70
physics.addBody(notchr, "static")
for i=1,2 do
for j=1,7 do
link[j] = display.newImageRect("img/chain.png", 14, 24)
link[j].x = 10 + (i*250)
link[j].y = 55 + (j*17)
physics.addBody(link[j], {density=2.0, friction=0, bounce=0})
myGroup:insert(link[j])
if j > 1 and j < 7 then
prevLink = link[j-1]
elseif j == 7 then
prevLink = ball
elseif j == 1 then
if i == 1 then
prevLink = notchl
else
prevLink = notchr
end
end
if prevLink == ball and i == 1 then
myJointsForLast[i] = physics.newJoint( "pivot", link[j], prevLink, link[j].x, link[j].y )
physics.newJoint( "pivot", link[j], link[j-1], 10 + (i*250), 45 + (j*17) )
elseif prevLink == ball and i == 2 then
myJointsForLast[i] = physics.newJoint( "pivot", link[j], prevLink, link[j].x, link[j].y )
physics.newJoint( "pivot", link[j], link[j-1], 10 + (i*250), 45 + (j*17) )
else
myJoints[#myJoints + 1] = physics.newJoint( "pivot", link[j], prevLink, 10 + (i*250), 45 + (j*17) )
end
end
end