Ragdoll Help!!

Okay so I found this really cool example that makes a ragdoll react to gravity like its suppose to http://developer.anscamobile.com/code/ragdoll-example… So I thought it would be AWESOME to have a toy doll in this kids app react the same way when the kids drag a toy doll to a toy chest… I am very new at this concept and am getting really confused in how to connect joints… If someone can help me connect something together… Like the arm to the body that would be really AWESOME… This is my code so far

[lua]local physics = require(“physics”)
physics.start()
physics.setDrawMode(“hybrid”)

– values
local props = { friction=1, density=1, bounce=0.1 }

local doll = display.newGroup()
local scene = display.newGroup()

– scene
scene.floor = display.newRect ( scene, 0, 750, 1024, 10 )
scene.topWall = display.newRect ( scene, 0, 0, 1024, 10 )
scene.leftWall = display.newRect ( scene, 0, 5, 10, 1020 )
scene.rightWall = display.newRect ( scene, 1015, 5, 10, 1020 )

physics.addBody( scene.floor, “static”, props )
physics.addBody( scene.topWall, “static”, props )
physics.addBody( scene.leftWall, “static”, props )
physics.addBody( scene.rightWall, “static”, props )

local doll_head = display.newImageRect(doll, “dollHead.png”, 128,79)
doll_head.x = 150; doll_head.y = 60
physics.addBody(doll_head,“dynamic”, { radius=30, density=0.8 })

local doll_leftHand = display.newImageRect(doll, “dollleftArm.png”, 55,33)
doll_leftHand.x = 98; doll_leftHand.y = 130
physics.addBody(doll_leftHand,“dynamic”, { radius=30, density=0.8 })

local doll_rightHand = display.newImageRect(doll, “dollrightArm.png”, 65,33)
doll_rightHand.x = 200; doll_rightHand.y = 130

local doll_body = display.newImageRect(doll, “dollBody.png”, 113,94)
doll_body.x = 150; doll_body.y = 150[/lua]

Thanks for any help!!! [import]uid: 51459 topic_id: 22624 reply_id: 322624[/import]

Okay so i read a little on joints from here http://developer.anscamobile.com/content/game-edition-physics-joints

and I think that there is some connection happening with the head and body but the head seems to be separated from the body… How do I bring them closer together…

Here’s my code…
[lua]local physics = require(“physics”)
physics.start()
physics.setDrawMode(“hybrid”)

– values
local props = { friction=1, density=1, bounce=0.1 }

local doll = display.newGroup()
local scene = display.newGroup()

– scene
scene.floor = display.newRect ( scene, 0, 750, 1024, 10 )
scene.topWall = display.newRect ( scene, 0, 0, 1024, 10 )
scene.leftWall = display.newRect ( scene, 0, 5, 10, 1020 )
scene.rightWall = display.newRect ( scene, 1015, 5, 10, 1020 )

physics.addBody( scene.floor, “static”, props )
physics.addBody( scene.topWall, “static”, props )
physics.addBody( scene.leftWall, “static”, props )
physics.addBody( scene.rightWall, “static”, props )
local doll_head = display.newImageRect(doll, “dollHead.png”, 128,79)
doll_head.x = 150; doll_head.y = 60
physics.addBody(doll_head,“dynamic”, { radius=30, density=0.8 })

local doll_leftHand = display.newImageRect(doll, “dollleftArm.png”, 55,33)
doll_leftHand.x = 98; doll_leftHand.y = 130
physics.addBody(doll_leftHand,“dynamic”, { radius=30, density=0.8 })
local doll_rightHand = display.newImageRect(doll, “dollrightArm.png”, 65,33)
doll_rightHand.x = 200; doll_rightHand.y = 130

local doll_body = display.newImageRect(doll, “dollBody.png”, 113,94)
doll_body.x = 150; doll_body.y = 150
physics.addBody(doll_body,“dynamic”, { density=0.8 })

myJoint = physics.newJoint( “weld”, doll_head, doll_body, 200,300 )[/lua]

THANKS (:
[import]uid: 51459 topic_id: 22624 reply_id: 90201[/import]

Just a heads up, I had a really tough time with ragdolls because the joints are too elastic and if one of the body parts gets caught on something, it will just stretch off the body. If you do a quick search on the forums you will probably find a few threads about it. [import]uid: 31262 topic_id: 22624 reply_id: 90229[/import]

okay thanks 30below!! I am not trying to do anything too fancy with it… just want it for looks… when you drag the doll around on the screen it will look as if you are dragging a real doll… I was able to connect all the body parts to the doll. I am just running into one small issue… The legs are too stiff… I want them to spread apart and do a split when they land on the ground… Here is my code

[lua]local physics = require(“physics”)
physics.start()
physics.setGravity(0,10)
physics.setDrawMode(“hybrid”)

– values
local props = { friction=1, density=1, bounce=0.1 }

local doll = display.newGroup()
local scene = display.newGroup()

– scene
scene.floor = display.newRect ( scene, 0, 400, 1024, 10 )
scene.topWall = display.newRect ( scene, 0, 0, 1024, 10 )
scene.leftWall = display.newRect ( scene, 0, 5, 10, 1020 )
scene.rightWall = display.newRect ( scene, 1015, 5, 10, 1020 )

physics.addBody( scene.floor, “static”, props )
physics.addBody( scene.topWall, “static”, props )
physics.addBody( scene.leftWall, “static”, props )
physics.addBody( scene.rightWall, “static”, props )

local doll_head = display.newImageRect(doll, “dollHead.png”, 128,79)
doll_head.x = 150; doll_head.y = 60
physics.addBody(doll_head,“dynamic”,{ friction=1, density=1, bounce=0.1, radius=20 })

local doll_body = display.newImageRect(doll, “dollBody.png”, 113,94)
doll_body.x = doll_head.x
doll_body.y = doll_head.y + 65
physics.addBody(doll_body,“dynamic”,props)

local doll_leftArm = display.newImageRect(doll, “dollleftArm.png”, 55,33)
doll_leftArm.x = doll_body.x - 55
doll_leftArm.y = doll_body.y -15
physics.addBody(doll_leftArm,“dynamic”,props)

local doll_rightArm = display.newImageRect(doll, “dollrightArm.png”, 65,33)
doll_rightArm.x = doll_body.x + 50
doll_rightArm.y = doll_body.y - 15
physics.addBody(doll_rightArm,“dynamic”,props)

local doll_leftLeg = display.newImageRect(doll, “dollleftLeg.png”, 32,68)
doll_leftLeg.x = doll_body.x
doll_leftLeg.y = doll_body.y + 55
physics.addBody(doll_leftLeg,“dynamic”,props)

local doll_rightLeg = display.newImageRect(doll, “dollrightLeg.png”, 36,68)
doll_rightLeg.x = doll_body.x + 20
doll_rightLeg.y = doll_body.y + 55
physics.addBody(doll_rightLeg,“dynamic”,props)

local doll_rightShoe = display.newImageRect(doll, “dollrightShoe.png”, 36,30)
doll_rightShoe.x = doll_rightLeg.x
doll_rightShoe.y = doll_rightShoe.y +218
physics.addBody(doll_rightShoe,“dynamic”,props)

local doll_leftShoe = display.newImageRect(doll, “dollrightShoe.png”, 36,25)
doll_leftShoe.x = doll_leftLeg.x - 5
doll_leftShoe.y = doll_leftShoe.y + 218
physics.addBody(doll_leftShoe,“dynamic”,props)

doll:insert(doll_head)
doll:insert(doll_leftArm)
doll:insert(doll_rightArm)
doll:insert(doll_rightShoe)
doll:insert(doll_leftShoe)
doll:insert(doll_leftLeg)
doll:insert(doll_rightLeg)
doll:insert(doll_body)

doll_head_joint = physics.newJoint(“pivot”, doll_head, doll_body, doll_head.x, doll_head.y + doll_head.height*0.5)
doll_leftArm_joint = physics.newJoint(“pivot”, doll_leftArm, doll_body, doll_body.x + 30, doll_body.y - 40)
doll_rightArm_joint = physics.newJoint(“pivot”, doll_rightArm, doll_body, doll_body.x + 30, doll_body.y - 40)
doll_leftLeg_joint = physics.newJoint(“pivot”, doll_leftLeg, doll_body, doll_body.x + 30, doll_body.y - 40)
doll_rightLeg_joint = physics.newJoint(“pivot”, doll_rightLeg, doll_body, doll_body.x + 30, doll_body.y - 40)
doll_rightShoe_joint = physics.newJoint(“weld”, doll_rightShoe, doll_rightLeg, doll_rightLeg.x + 30, doll_rightLeg.y - 40)
doll_leftShoe_joint = physics.newJoint(“weld”, doll_leftShoe, doll_leftLeg, doll_leftLeg.x + 30, doll_leftLeg.y - 40)

function addRotationLimits( joints, limit )
for i=1, #joints do
local joint = joints[i]
joint.isLimitEnabled = true
joint:setRotationLimits( -limit, limit )
end
end

function addRotationLimits2( joints, limit )
for i=1, #joints do
local joint = joints[i]
joint.isLimitEnabled = true
joint:setRotationLimits( -limit, limit )
end
end

function addRotationLimits3( joints, limit )
for i=1, #joints do
local joint = joints[i]
joint.isLimitEnabled = true
joint:setRotationLimits( -limit, limit )
end
end

addRotationLimits(
{ doll_head_joint },
45
)

addRotationLimits2(
{ doll_leftArm_joint, doll_rightArm_joint},
5
)

addRotationLimits3(
{ doll_leftLeg_joint, doll_rightLeg_joint },
10
)

function touch( event )
print(“touch”)
if (event.phase == ‘began’) then
doll.touch = physics.newJoint( “touch”, event.target, event.x, event.y )
print(doll.touch.maxForce,doll.touch.frequency,doll.touch.dampingRatio)
doll.touch:setTarget( event.x, event.y )
display.getCurrentStage():setFocus( event.target )
elseif (event.phase == ‘moved’ and doll.touch ~= nil) then
doll.touch:setTarget( event.x, event.y )
elseif (doll.touch ~= nil) then
doll.touch:removeSelf()
doll.touch = nil
display.getCurrentStage():setFocus( nil )
end

return true
end

function addTouch( dg )
for i=1, dg.numChildren do
dg[i]:addEventListener( “touch”, touch )
end
end

addTouch( doll )[/lua]

THANKS!! [import]uid: 51459 topic_id: 22624 reply_id: 90249[/import]

Can’t test your code because no image files. Anyways this is just some old test code I dug up when I was originally playing with it. It’s just a very basic ragdoll figure you can drag around. I haven’t touched this code in about a year, when I was first playing around with Corona so take what you will from it. I took the drag function from the Drag Platforms sample project. Again, old code from when I first started… hope it helps.
[lua]local physics = require(“physics”)
physics.start()

display.setStatusBar( display.HiddenStatusBar )

physics.setGravity( 0, 20 )

local man = display.newGroup()
local ground = display.newRect( 0, 450, 350, 50 )
physics.addBody( ground, “static”, { friction=0.6 } )
local head = display.newCircle( 212, 180, 20 )
local chest = display.newRect( 200, 200, 25, 60)
local Larm = display.newRect( 185, 200, 10, 50)
Larm:rotate(10)
local Rarm = display.newRect( 230, 200, 10, 50)
Rarm:rotate(-10)
local Lleg = display.newRect( 200, 260, 10, 60 )
local Rleg = display.newRect( 215, 260, 10, 60 )

physics.addBody(head, { density = 1.0, friction = 0.3, bounce = 0.4, radius = 20 } )
physics.addBody( chest, { density=0.5, friction=1, bounce=.3 } )
physics.addBody( Larm, { density=0.5, friction=1, bounce=.3 } )
physics.addBody( Rarm, { density=0.5, friction=1, bounce=.3 } )
physics.addBody( Lleg, { density=0.5, friction=1, bounce=.3 } )
physics.addBody( Rleg, { density=0.5, friction=1, bounce=.3 } )

local headchest = physics.newJoint( “pivot”, head, chest, 212,200 )
headchest.isLimitEnabled = true
headchest:setRotationLimits(-10, 10)
local chestLarm = physics.newJoint(“pivot”, chest, Larm, 200, 203)
chestLarm.isLimitEnabled = true
chestLarm:setRotationLimits(-5, 90)
local chestRarm = physics.newJoint(“pivot”, chest, Rarm, 230, 203)
chestRarm.isLimitEnabled = true
chestRarm:setRotationLimits(-90, 0)
local chestLleg = physics.newJoint(“pivot”, chest, Lleg, 200, 260)
chestLleg.isLimitEnabled = true
chestLleg:setRotationLimits(-45, 90)
local chestRleg = physics.newJoint(“pivot”, chest, Rleg, 215, 260)
chestRleg.isLimitEnabled = true
chestRleg:setRotationLimits(-90, 45)
– A basic function for dragging physics objects
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
if t.y > platform1.y then
t.y = platform1.y
end

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

– Add touch event listeners to objects

head:addEventListener( “touch”, startDrag )
chest:addEventListener( “touch”, startDrag )
Larm:addEventListener( “touch”, startDrag )
Rarm:addEventListener( “touch”, startDrag )
Rleg:addEventListener( “touch”, startDrag )
Lleg:addEventListener( “touch”, startDrag )[/lua] [import]uid: 31262 topic_id: 22624 reply_id: 90256[/import]

THANKS!! That does help a little!! [import]uid: 51459 topic_id: 22624 reply_id: 90267[/import]