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!