Snake tail effect using joints

I created trail using joints.But I when I move it,it starts shaking weirdly after a while.

It is not steady or smooth as in snake vs blocks.

Code is below

local centerX = display.contentCenterX local centerY = display.contentCenterY local \_W = display.contentWidth local \_H = display.contentHeight local physics = require("physics") physics.start() local sg = display.newGroup() local xc = display.contentCenterX local yc = display.contentCenterY local w = display.contentWidth local h = display.contentHeight math.randomseed(os.clock()) local r = math.random physics.setDrawMode("hybrid") local xv, px, pb, ccv for i = 1, 10 do xv = display.newRect(centerX, centerY, 30, 30) xv.x = xc if i \> 1 then physics.addBody(xv, "dynamic", {density = 2.0, friction = 0, bounce = 0}) xv.isSleepingAllowed = false xv.y = px + xv.contentHeight local c = physics.newJoint("pivot", pb, xv, pb.x, pb.y) else physics.addBody(xv, "static", {density = 2.0, friction = 0, bounce = 0}) xv.y = yc ccv = xv end px = xv.y pb = xv end local function moveTheSnake(event) ccv.x = event.x end Runtime:addEventListener("touch", moveTheSnake)

Any suggestions?

Thanks!

Don’t use joints, linked to joints, linked to joints, …  That is too heavy (calculation wise) and won’t ever behave nicely. 

Use enterframe listener(s).

https://www.youtube.com/watch?v=1H4jATyCbew&feature=youtu.be

Download entire RGFreeStuff (https://github.com/roaminggamer/RG_FreeStuff) and look here:

RG_FreeStuff\AskEd\2015\05\followTheLeader

or download files from here, one by one:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/05/followTheLeader

thanks RG!

Don’t use joints, linked to joints, linked to joints, …  That is too heavy (calculation wise) and won’t ever behave nicely. 

Use enterframe listener(s).

https://www.youtube.com/watch?v=1H4jATyCbew&feature=youtu.be

Download entire RGFreeStuff (https://github.com/roaminggamer/RG_FreeStuff) and look here:

RG_FreeStuff\AskEd\2015\05\followTheLeader

or download files from here, one by one:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/05/followTheLeader

thanks RG!