I made a ragdoll and need it standing. I actually did it but its head is falling down to left. Tried to change the density values but didn’t help, also gave angularDamping but it just slows down the process, head is still falling. I actually want the body(also head) is a bit shaky but shouldn’t fall or be ruined. Code about ragdoll is here;
local composer = require( "composer" )
local scene = composer.newScene()
local physics = require("physics")
physics.start( )
physics.setGravity( 0, 12 )
--physics.setDrawMode( "hybrid" )
physics.setScale( 50 )
local ragdollDensity = 0.02
local ragdollFriction = 0.4
local ragdollBounce = 0.4
local ragdollFilter1 = {categoryBits=1, maskBits=3}
local ragdollFilter2 = {categoryBits=4, maskBits=5}
local background = display.newImageRect("res/background/b1.png", 1280, 720)
background.x = display.contentCenterX
background.y = display.contentCenterY
local platform1 = display.newRect(650, 470, 540, 38)
platform1:setFillColor( 0.6, 0.2, 0 )
physics.addBody(platform1, "static")
-- Ragdoll 1
local head = display.newImageRect("res/head/ninja.png", 63, 57 )
head.x = display.contentCenterX+60
head.y = display.contentCenterY+20
local headBounds = head.contentBounds
physics.addBody(head, "dynamic", {radius=22, density=ragdollDensity, friction=ragdollFriction,
bounce=ragdollBounce, filter=ragdollFilter1})
local vertices = {
display.contentCenterX+15, display.contentCenterY+125,
display.contentCenterX+65, display.contentCenterY+125,
display.contentCenterX+55, display.contentCenterY+165,
display.contentCenterX+25, display.contentCenterY+165
}
local torso = display.newPolygon(display.contentCenterX+60, headBounds.yMax,
vertices)
torso.anchorY = 0
local torsoBounds = torso.contentBounds
torso:setFillColor( 0,0,1 )
physics.addBody(torso, "dynamic", {density=ragdollDensity, friction=ragdollFriction,
bounce=ragdollBounce, filter=ragdollFilter1})
local lArm = display.newRoundedRect(torsoBounds.xMin, torsoBounds.yMin,
display.contentWidth*.012, display.contentHeight*.06, 5)
lArm.anchorX = 1
lArm.anchorY = 0
lArm:setFillColor( 0,0,1 )
physics.addBody(lArm, "dynamic", {density=ragdollDensity, friction=ragdollFriction,
bounce=ragdollBounce, filter=ragdollFilter1})
local rArm = display.newRoundedRect(torsoBounds.xMax, torsoBounds.yMin,
display.contentWidth*.012, display.contentHeight*.06, 5)
rArm.anchorX = 0
rArm.anchorY = 0
rArm:setFillColor( 0,0,1 )
physics.addBody(rArm, "dynamic", {density=ragdollDensity, friction=ragdollFriction,
bounce=ragdollBounce, filter=ragdollFilter1})
local rLeg = display.newRoundedRect(torso.x + torso.width/2, torsoBounds.yMax,
display.contentWidth*.015, display.contentHeight*.075, 5)
rLeg.anchorX = 1
rLeg.anchorY = 0
rLeg:setFillColor( 0,0,1 )
physics.addBody(rLeg, "dynamic", {density=ragdollDensity, friction=ragdollFriction,
bounce=ragdollBounce, filter=ragdollFilter1})
local lLeg = display.newRoundedRect(torso.x - torso.width/2, torsoBounds.yMax,
display.contentWidth*.015, display.contentHeight*.075, 5)
lLeg.anchorX = 0
lLeg.anchorY = 0
lLeg:setFillColor( 0,0,1 )
physics.addBody(lLeg, "dynamic", {density=ragdollDensity, friction=ragdollFriction,
bounce=ragdollBounce, filter=ragdollFilter1})
local headToTorso = physics.newJoint("pivot", head, torso, head.x, headBounds.yMax)
local torsoTolArm = physics.newJoint("pivot", torso, lArm, torsoBounds.xMin, torsoBounds.yMin)
local torsoTorArm = physics.newJoint("pivot", torso, rArm, torsoBounds.xMax, torsoBounds.yMin)
local torsoTolLeg = physics.newJoint("pivot", torso, lLeg, torso.x - lLeg.width/2, torsoBounds.yMax)
local torsoTorLeg = physics.newJoint("pivot", torso, rLeg, torso.x + rLeg.width/2, torsoBounds.yMax)
Here is a picture;
Couldn’t find a way to prevent head falling, also if you can help me to make the ragdoll just a bit shaky, i’d appreciate it.