Hi
I’m learning corona and trying to build game. For starters I have taken the DragPlatforms sample file. From that I created my doll, added physics and joints. As I drag the objects, all the joints get over stretched.
Can you please help?
local physics = require( "physics" ) physics.start() physics.setContinuous( false ) physics.setDrawMode( "hybrid" ) display.setStatusBar( display.HiddenStatusBar ) height = display.contentHeight width = display.contentWidth local wallBottom = display.newRect(0,height-20,width,20) physics.addBody(wallBottom, "static", { density=5, friction=0.5, bounce=0.3 } ) local function setFill(ob, param) ob:setFillColor(param[1], param[2], param[3], param[4] or 255) end local colorDoll = {255, 102, 102, 255} local doll = display.newGroup() local w, h, r = 250, height - 460, 8 local head = display.newCircle(doll,w,h+6,21) setFill(head, colorClimber) local neck = display.newCircle(doll,w,h+36,r) local torso1 = display.newRect(doll,w-23,h+42,46,18) local torso2 = display.newRect(doll,w-20,h+57,40,18) local torso3 = display.newRect(doll,w-17,h+72,34,18) local torso4 = display.newRect(doll,w-14,h+90,28,12) local torso5 = display.newRect(doll,w-16,h+102,32,15) local torso6 = display.newRect(doll,w-18,h+117,36,15) local shoulderL = display.newCircle(doll,w-31,h+50,r) setFill(shoulderL, colorDoll) local shoulderR = display.newCircle(doll,w+31,h+50,r) setFill(shoulderR, colorDoll) local hippL = display.newCircle(doll,w-10,h+140,r) setFill(hippL, colorDoll) local hippR = display.newCircle(doll,w+10,h+140,r) setFill(hippR, colorDoll) local legTopL = display.newRect(doll,w-18,h+148,16,50) local legTopR = display.newRect(doll,w+2,h+148,16,50) local kneeL = display.newCircle(doll,w-10,h+206,r) setFill(kneeL, colorDoll) local kneeR = display.newCircle(doll,w+10,h+206,r) setFill(kneeR, colorDoll) local legBottomL = display.newRect(doll,w-15,h+214,10,60) local legBottomR = display.newRect(doll,w+5,h+214,10,60) local footL = display.newRect(doll,w-34,h+274,30,15) footL.isPlatform = true local footR = display.newRect(doll,w+3,h+274,30,15) footR.isPlatform = true local armTopL = display.newRect(doll,w-35,h+58,8,30) local armTopR = display.newRect(doll,w+27,h+58,8,30) local elbowL = display.newCircle(doll,w-31,h+96,r) setFill(elbowL, colorDoll) local elbowR = display.newCircle(doll,w+31,h+96,r) setFill(elbowR, colorDoll) local armBottomL = display.newRect(doll,w-35,h+104,8,40) local armBottomR = display.newRect(doll,w+27,h+104,8,40) local handL = display.newCircle(doll,w-31,h+156,r+4) handL.isPlatform = true local handR = display.newCircle(doll,w+31,h+156,r+4) handR.isPlatform = true setFill(handL, colorDoll) setFill(handR, colorDoll) local d, f, b = 3, 0.75, 0.05 physics.addBody(head, "dynamic", { density=d, friction=f, bounce=b, radius=21 } ) physics.addBody(neck, "dynamic", { density=d, friction=f, bounce=b, radius=r } ) physics.addBody(shoulderL, "dynamic", { density=d, friction=f, bounce=b, radius=r } ) physics.addBody(shoulderR, "dynamic", { density=d, friction=f, bounce=b, radius=r } ) physics.addBody(hippL, "dynamic", { density=d, friction=f, bounce=b, radius=r } ) physics.addBody(hippR, "dynamic", { density=d, friction=f, bounce=b, radius=r } ) physics.addBody(elbowL, "dynamic", { density=d, friction=f, bounce=b, radius=r } ) physics.addBody(elbowR, "dynamic", { density=d, friction=f, bounce=b, radius=r } ) physics.addBody(kneeL, "dynamic", { density=d, friction=f, bounce=b, radius=r } ) physics.addBody(kneeR, "dynamic", { density=d, friction=f, bounce=b, radius=r } ) physics.addBody(handL, "kinematic", { density=d, friction=f, bounce=b, radius=r+4 } ) physics.addBody(handR, "kinematic", { density=d, friction=f, bounce=b, radius=r+4 } ) physics.addBody(torso1, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(torso2, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(torso3, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(torso4, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(torso5, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(torso6, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(legBottomL, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(legBottomR, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(legTopL, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(legTopR, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(armBottomL, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(armBottomR, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(armTopL, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(armTopR, "dynamic", { density=d, friction=f, bounce=b } ) physics.addBody(footL, "kinematic", { density=d, friction=f, bounce=b } ) physics.addBody(footR, "kinematic", { density=d, friction=f, bounce=b } ) local function addFrictionJoint(a, b, posX, posY, lowerAngle, upperAngle, mT) local j = physics.newJoint ( "pivot", a, b, posX, posY, rFrom, rTo) j.isLimitEnabled = true j:setRotationLimits (lowerAngle, upperAngle) j.angularDamping = 5000 j.linearDamping = 0.7 return j end -- JOINTS addFrictionJoint( neck, head, w, (h+10), 0, 0 ) addFrictionJoint( neck, torso1, w, (h+42), 0, 0 ) addFrictionJoint( torso2, torso1, w, (h+57), -10, 10 ) addFrictionJoint( torso2, torso3, w, (h+72), -10, 10 ) addFrictionJoint( torso4, torso3, w, (h+90), -10, 10 ) addFrictionJoint( torso4, torso5, w, (h+102), -10, 10 ) addFrictionJoint( torso6, torso5, w, (h+117), -10, 10 ) addFrictionJoint( torso6, hippL, (w-10), (h+132), -5, 5 ) addFrictionJoint( torso6, hippR, (w+10), (h+132), -5, 5 ) addFrictionJoint( legTopR, hippR, (w+10), (h+148), -5, 5 ) addFrictionJoint( legTopL, hippL, (w-10), (h+148), -45, 45 ) addFrictionJoint( legTopL, kneeL, (w-10), (h+198), -5, 5 ) addFrictionJoint( legTopR, kneeR, (w+10), (h+198), -5, 5 ) addFrictionJoint( legBottomR, kneeR, (w+10), (h+214), -45, 0 ) addFrictionJoint( legBottomL, kneeL, (w-10), (h+214), -0, 45 ) addFrictionJoint( legBottomR, footR, (w+10), (h+274), -10, 10 ) addFrictionJoint( legBottomL, footL, (w-10), (h+274), -10, 10 ) addFrictionJoint( shoulderL, torso1, (w-23), (h+50), -40, 40 ) addFrictionJoint( shoulderR, torso1, (w+23), (h+50), -40, 40 ) addFrictionJoint( shoulderR, armTopR, (w+31), (h+58), -90, 90 ) addFrictionJoint( shoulderL, armTopL, (w-31), (h+58), -90, 90 ) addFrictionJoint( elbowL, armTopL, (w-31), (h+88), -5, 5 ) addFrictionJoint( elbowR, armTopR, (w+31), (h+88), -5, 5 ) addFrictionJoint( elbowR, armBottomR, (w+31), (h+104), -45, 45 ) addFrictionJoint( elbowL, armBottomL, (w-31), (h+104), -45, 45 ) addFrictionJoint( handL, armBottomL, (w-31), (h+144), -5, 5 ) addFrictionJoint( handR, armBottomR, (w+31), (h+144), -5, 5 ) local function startDrag( event ) local t = event.target local phase = event.phase if "began" == phase then display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y -- Make body type temporarily "kinematic" (to avoid gravitional forces) event.target.bodyType = "kinematic" -- Stop current motion, if any event.target:setLinearVelocity( 0, 0 ) event.target.angularVelocity = 0 elseif t.isFocus then if "moved" == phase then t.x = event.x - t.x0 t.y = event.y - t.y0 elseif "ended" == phase or "cancelled" == phase then display.getCurrentStage():setFocus( nil ) t.isFocus = false -- Switch body type back to "dynamic", unless we've marked this sprite as a platform if ( not event.target.isPlatform ) then event.target.bodyType = "dynamic" end end end -- Stop further propagation of touch event! return true end handL:addEventListener( "touch", startDrag ) handR:addEventListener( "touch", startDrag ) footL:addEventListener( "touch", startDrag ) footR:addEventListener( "touch", startDrag )