just been experimenting with physics.newJoint and have been able to connect 3 circles up just fine like a worm. The movement is fine with 3 joints but when I get to a larger number say 10 the other joints lag behind and cause for gaps to be between the circles, any way of speeding up the movement of the joints so it can at all times move as a whole. [import]uid: 87730 topic_id: 35577 reply_id: 335577[/import]
Hi @jazzarssoul,
What kind of joints are you using? Depending on which, you should be able to adjust the properties of those joints to be more (or less) stretchy, and thus, the worm will move as you expect. Typically, joints just need some tweaking, and you must test them carefully under all game circumstances to ensure they don’t freak out.
Brent [import]uid: 200026 topic_id: 35577 reply_id: 141480[/import]
Hi @jazzarssoul,
What kind of joints are you using? Depending on which, you should be able to adjust the properties of those joints to be more (or less) stretchy, and thus, the worm will move as you expect. Typically, joints just need some tweaking, and you must test them carefully under all game circumstances to ensure they don’t freak out.
Brent [import]uid: 200026 topic_id: 35577 reply_id: 141480[/import]
Brent, I’m just using pivot points connected via for loop to one after the other [import]uid: 87730 topic_id: 35577 reply_id: 142577[/import]
Hi @jazzarssoul,
Did you follow the “Chains” demo in the “Physics” folder of the Corona SDK “SampleCode” folder? This demo shows a series of many chain links joined, and they don’t separate. If you did follow this code, and your “worm” is still falling apart, I think the issue must be elsewhere in your physics setup.
Brent [import]uid: 200026 topic_id: 35577 reply_id: 142582[/import]
Hey there Brent the chains demo is exactly what I followed but as I apply movement to just the head of the worm via joystick
upon moving the worm around instead of an instant glue like connection between body segments it appears to have a stretch like approach to it as in the first 2 segments behind the head are fine with keeping up to the heads movement but for segments say 9 and 10 lag behind with a gap between them [import]uid: 87730 topic_id: 35577 reply_id: 143086[/import]
Brent, I’m just using pivot points connected via for loop to one after the other [import]uid: 87730 topic_id: 35577 reply_id: 142577[/import]
Hi @jazzarssoul,
Did you follow the “Chains” demo in the “Physics” folder of the Corona SDK “SampleCode” folder? This demo shows a series of many chain links joined, and they don’t separate. If you did follow this code, and your “worm” is still falling apart, I think the issue must be elsewhere in your physics setup.
Brent [import]uid: 200026 topic_id: 35577 reply_id: 142582[/import]
Hey there Brent the chains demo is exactly what I followed but as I apply movement to just the head of the worm via joystick
upon moving the worm around instead of an instant glue like connection between body segments it appears to have a stretch like approach to it as in the first 2 segments behind the head are fine with keeping up to the heads movement but for segments say 9 and 10 lag behind with a gap between them [import]uid: 87730 topic_id: 35577 reply_id: 143086[/import]
Hi @jazzarssoul,
Sorry for the late reply, I’ve been swamped. Anyway, I just tossed together this quick “worm” scenario using pivot joints, and it seems to be working just fine… no separation of parts. Did you by chance have the density of your worm pieces set extremely high, such that Box2D might have been struggling to keep them together?
Anyway, check this out… I also set a rotation limit of each pivot joint to 45 degrees off its “normal”, which helps the worm look more natural.
Regards,
Brent
[code]
local myJoints = {}
local prevLink
local link = {}
for j = 1,25 do
link[j] = display.newRect( 0,0,10,22 ) ; link[j]:setFillColor(200)
link[j].x = display.contentWidth/2
link[j].y = 55 + (j*25)
physics.addBody( link[j], { density=0.2, friction=0, bounce=0, filter={ categoryBits=1, maskBits=2} } )
if (j > 1) then
prevLink = link[j-1]
myJoints[#myJoints+1] = physics.newJoint( “pivot”, prevLink, link[j], display.contentWidth/2, 46+(j*25) )
myJoints[#myJoints].isLimitEnabled = true
myJoints[#myJoints]:setRotationLimits( -45, 45 )
end
end
local function changeDir()
local snakeDir
local dir = math.random(1,4)
if ( dir == 1 ) then snakeDir = {0,-40}
elseif ( dir == 2 ) then snakeDir = {40,0}
elseif ( dir == 3 ) then snakeDir = {0,40}
else snakeDir = {-40,0}
end
local mult = math.random(1,3)
local head = link[#link]
head:applyForce( snakeDir[1]*mult, snakeDir[2]*mult, head.x, head.y )
end
timer.performWithDelay( 1000, changeDir, 0 )
[/code] [import]uid: 200026 topic_id: 35577 reply_id: 143953[/import]
thank you very much here Brent, density has done the job
[import]uid: 87730 topic_id: 35577 reply_id: 144005[/import]
Hi @jazzarssoul,
Sorry for the late reply, I’ve been swamped. Anyway, I just tossed together this quick “worm” scenario using pivot joints, and it seems to be working just fine… no separation of parts. Did you by chance have the density of your worm pieces set extremely high, such that Box2D might have been struggling to keep them together?
Anyway, check this out… I also set a rotation limit of each pivot joint to 45 degrees off its “normal”, which helps the worm look more natural.
Regards,
Brent
[code]
local myJoints = {}
local prevLink
local link = {}
for j = 1,25 do
link[j] = display.newRect( 0,0,10,22 ) ; link[j]:setFillColor(200)
link[j].x = display.contentWidth/2
link[j].y = 55 + (j*25)
physics.addBody( link[j], { density=0.2, friction=0, bounce=0, filter={ categoryBits=1, maskBits=2} } )
if (j > 1) then
prevLink = link[j-1]
myJoints[#myJoints+1] = physics.newJoint( “pivot”, prevLink, link[j], display.contentWidth/2, 46+(j*25) )
myJoints[#myJoints].isLimitEnabled = true
myJoints[#myJoints]:setRotationLimits( -45, 45 )
end
end
local function changeDir()
local snakeDir
local dir = math.random(1,4)
if ( dir == 1 ) then snakeDir = {0,-40}
elseif ( dir == 2 ) then snakeDir = {40,0}
elseif ( dir == 3 ) then snakeDir = {0,40}
else snakeDir = {-40,0}
end
local mult = math.random(1,3)
local head = link[#link]
head:applyForce( snakeDir[1]*mult, snakeDir[2]*mult, head.x, head.y )
end
timer.performWithDelay( 1000, changeDir, 0 )
[/code] [import]uid: 200026 topic_id: 35577 reply_id: 143953[/import]
thank you very much here Brent, density has done the job
[import]uid: 87730 topic_id: 35577 reply_id: 144005[/import]
Hey there Brent the chains demo is exactly what I followed but as I apply movement to just the head of the worm via joystick
upon moving the worm around instead of an instant glue like connection between body segments it appears to have a stretch like approach to it as in the first 2 segments behind the head are fine with keeping up to the heads movement but for segments say 9 and 10 lag behind with a gap between them [import]uid: 87730 topic_id: 35577 reply_id: 143086[/import]
Hi @jazzarssoul,
Sorry for the late reply, I’ve been swamped. Anyway, I just tossed together this quick “worm” scenario using pivot joints, and it seems to be working just fine… no separation of parts. Did you by chance have the density of your worm pieces set extremely high, such that Box2D might have been struggling to keep them together?
Anyway, check this out… I also set a rotation limit of each pivot joint to 45 degrees off its “normal”, which helps the worm look more natural.
Regards,
Brent
[code]
local myJoints = {}
local prevLink
local link = {}
for j = 1,25 do
link[j] = display.newRect( 0,0,10,22 ) ; link[j]:setFillColor(200)
link[j].x = display.contentWidth/2
link[j].y = 55 + (j*25)
physics.addBody( link[j], { density=0.2, friction=0, bounce=0, filter={ categoryBits=1, maskBits=2} } )
if (j > 1) then
prevLink = link[j-1]
myJoints[#myJoints+1] = physics.newJoint( “pivot”, prevLink, link[j], display.contentWidth/2, 46+(j*25) )
myJoints[#myJoints].isLimitEnabled = true
myJoints[#myJoints]:setRotationLimits( -45, 45 )
end
end
local function changeDir()
local snakeDir
local dir = math.random(1,4)
if ( dir == 1 ) then snakeDir = {0,-40}
elseif ( dir == 2 ) then snakeDir = {40,0}
elseif ( dir == 3 ) then snakeDir = {0,40}
else snakeDir = {-40,0}
end
local mult = math.random(1,3)
local head = link[#link]
head:applyForce( snakeDir[1]*mult, snakeDir[2]*mult, head.x, head.y )
end
timer.performWithDelay( 1000, changeDir, 0 )
[/code] [import]uid: 200026 topic_id: 35577 reply_id: 143953[/import]
thank you very much here Brent, density has done the job
[import]uid: 87730 topic_id: 35577 reply_id: 144005[/import]
Hey there Brent the chains demo is exactly what I followed but as I apply movement to just the head of the worm via joystick
upon moving the worm around instead of an instant glue like connection between body segments it appears to have a stretch like approach to it as in the first 2 segments behind the head are fine with keeping up to the heads movement but for segments say 9 and 10 lag behind with a gap between them [import]uid: 87730 topic_id: 35577 reply_id: 143086[/import]
Hi @jazzarssoul,
Sorry for the late reply, I’ve been swamped. Anyway, I just tossed together this quick “worm” scenario using pivot joints, and it seems to be working just fine… no separation of parts. Did you by chance have the density of your worm pieces set extremely high, such that Box2D might have been struggling to keep them together?
Anyway, check this out… I also set a rotation limit of each pivot joint to 45 degrees off its “normal”, which helps the worm look more natural.
Regards,
Brent
[code]
local myJoints = {}
local prevLink
local link = {}
for j = 1,25 do
link[j] = display.newRect( 0,0,10,22 ) ; link[j]:setFillColor(200)
link[j].x = display.contentWidth/2
link[j].y = 55 + (j*25)
physics.addBody( link[j], { density=0.2, friction=0, bounce=0, filter={ categoryBits=1, maskBits=2} } )
if (j > 1) then
prevLink = link[j-1]
myJoints[#myJoints+1] = physics.newJoint( “pivot”, prevLink, link[j], display.contentWidth/2, 46+(j*25) )
myJoints[#myJoints].isLimitEnabled = true
myJoints[#myJoints]:setRotationLimits( -45, 45 )
end
end
local function changeDir()
local snakeDir
local dir = math.random(1,4)
if ( dir == 1 ) then snakeDir = {0,-40}
elseif ( dir == 2 ) then snakeDir = {40,0}
elseif ( dir == 3 ) then snakeDir = {0,40}
else snakeDir = {-40,0}
end
local mult = math.random(1,3)
local head = link[#link]
head:applyForce( snakeDir[1]*mult, snakeDir[2]*mult, head.x, head.y )
end
timer.performWithDelay( 1000, changeDir, 0 )
[/code] [import]uid: 200026 topic_id: 35577 reply_id: 143953[/import]
thank you very much here Brent, density has done the job
[import]uid: 87730 topic_id: 35577 reply_id: 144005[/import]