Are there any rag doll tutorials or any other info or help about making rag dolls with Corona? Did a search on the website but couldn’t find anything.
Thanks [import]uid: 48020 topic_id: 17983 reply_id: 317983[/import]
Are there any rag doll tutorials or any other info or help about making rag dolls with Corona? Did a search on the website but couldn’t find anything.
Thanks [import]uid: 48020 topic_id: 17983 reply_id: 317983[/import]
Not that I have seen, no - although this is a good suggestion for a tutorial.
I’ll have to keep in mind for a future Techority post 
Peach [import]uid: 52491 topic_id: 17983 reply_id: 68699[/import]
here it goes…
[code]
function newRagDoll(originX, originY)
–> Create Ragdoll Group
local spacing = 1
local ragdoll = display.newGroup ()
–********************************************************
– HEAD
–********************************************************
local head = display.newCircle( 0, 0, 9 )
head.x = originX - 3
head.y = originY - 3
head.name = “doll”
head:setFillColor (255, 255, 255, 128)
ragdoll:insert (head)
–********************************************************
–********************************************************
– TORSO
–********************************************************
local torsoA = display.newRect( 0, 0,18, 10 )
torsoA.x = originX
torsoA.y = originY + (head.height - 10)
torsoA:setFillColor (255, 255, 255, 128)
torsoA.name = “doll”
ragdoll:insert (torsoA)
local torsoB = display.newRect( 0, 0, 15, 10 )
torsoB.x = originX
torsoB.y = torsoA.y + (torsoA.height * 0.5) + spacing
torsoB:setFillColor (255, 255, 255, 128)
torsoB.name = “doll”
ragdoll:insert (torsoB)
torsoB:toBack()
local torsoC = display.newRect( 0, 0, 12, 10 )
torsoC.x = originX
torsoC.y = torsoB.y + (torsoB.height * 0.5) + spacing
torsoC:setFillColor (255, 255, 255, 128)
torsoC.name = “doll”
ragdoll:insert (torsoC)
torsoC:toBack()
local pelvis = display.newRect( 0, 0, 11, 10 )
pelvis.x = originX
pelvis.y = torsoC.y + (torsoC.height * 0.5) + spacing
pelvis:setFillColor (255, 255, 255, 128)
pelvis.name = “doll”
ragdoll:insert (pelvis)
pelvis:toBack()
–********************************************************
–********************************************************
– LEFT - RIGHT LEG
–********************************************************
local leftLegA = display.newRect( 0, 0, 7, 20 )
leftLegA.x = pelvis.x - ((pelvis.width - leftLegA.width) * 0.5)
leftLegA.y = pelvis.y + (leftLegA.height * 0.5) + spacing
leftLegA:setFillColor (255, 255, 255, 128)
leftLegA.name = “doll”
ragdoll:insert (leftLegA)
local rightLegA = display.newRect( 0, 0, 7, 20 )
rightLegA.x = pelvis.x + ((pelvis.width - rightLegA.width) * 0.5)
rightLegA.y = pelvis.y + (rightLegA.height * 0.5) + spacing
rightLegA:setFillColor (255, 255, 255, 128)
rightLegA.name = “doll”
ragdoll:insert (rightLegA)
local leftLegB = display.newRect( 0, 0, 7, 22 )
leftLegB.x = leftLegA.x
leftLegB.y = leftLegA.y + rightLegA.height - 5
leftLegB:setFillColor (255, 255, 255, 128)
leftLegB.name = “doll”
ragdoll:insert (leftLegB)
local rightLegB = display.newRect( 0, 0, 7, 22 )
rightLegB.x = rightLegA.x
rightLegB.y = rightLegA.y + rightLegA.height - 5
rightLegB:setFillColor (255, 255, 255, 128)
rightLegB.name = “doll”
ragdoll:insert (rightLegB)
–********************************************************
– RIGHT LEFT - ARM
–********************************************************
local leftArmA = display.newRect( 125, 70, 7, 18 )
leftArmA.x = torsoA.x - (torsoA.width * 0.5) - 3
leftArmA.y = torsoA.y + (leftArmA.height * 0.5) - 6
leftArmA:setFillColor (255, 255, 255, 128)
leftArmA.name = “doll”
ragdoll:insert (leftArmA)
local rightArmA = display.newRect( 185, 70, 7, 18 )
rightArmA.x = torsoA.x + (torsoA.width * 0.5) + 3
rightArmA.y = torsoA.y + (rightArmA.height * 0.5) - 6
rightArmA:setFillColor (255, 255, 255, 128)
rightArmA.name = “doll”
ragdoll:insert (rightArmA)
local leftArmB = display.newRect( 125, 105, 7, 15 )
leftArmB.x = leftArmA.x
leftArmB.y = leftArmA.y + (leftArmA.height) - 6
leftArmB:setFillColor (255, 255, 255, 128)
leftArmB.name = “doll”
ragdoll:insert (leftArmB)
local rightArmB = display.newRect( 185, 105, 7, 18 )
rightArmB.x = rightArmA.x
rightArmB.y = rightArmA.y + (rightArmA.height) - 6
rightArmB:setFillColor (255, 255, 255, 128)
rightArmB.name = “doll”
ragdoll:insert (rightArmB)
–********************************************************
– CONVERT TO PHYSICS
–********************************************************
physics.addBody (head , {density=0.2, friction=0.1, bounce=0.2, radius=16})
physics.addBody (torsoA , {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (torsoB , {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (torsoC , {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (pelvis , {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (leftLegA , {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (rightLegA, {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (leftLegB , {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (rightLegB, {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (leftArmA , {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (rightArmA, {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (leftArmB , {density=0.7, friction=0.1, bounce=0.2})
physics.addBody (rightArmB, {density=0.7, friction=0.1, bounce=0.2})
local neckJoint = physics.newJoint ( “pivot”, head, torsoA, torsoA.x, torsoA.y)
neckJoint.isLimitEnabled = true
neckJoint:setRotationLimits ( -22.5, 22.5 )
–neckJoint.isMotorEnabled = true
–neckJoint.motorSpeed = 0
–neckJoint.maxMotorTorque = 2
local backboneA = physics.newJoint ( “pivot”, torsoA, torsoB, torsoB.x, torsoB.y )
backboneA.isLimitEnabled = true
backboneA:setRotationLimits ( -22.5, 22.5 )
–backboneA.isMotorEnabled = true
–backboneA.motorSpeed = 0
–backboneA.maxMotorTorque = 2
local backboneB = physics.newJoint ( “pivot”, torsoB, torsoC, torsoC.x, torsoC.y )
backboneB.isLimitEnabled = true
backboneB:setRotationLimits ( -22.5, 22.5 )
–backboneB.isMotorEnabled = true
–backboneB.motorSpeed = 0
–backboneB.maxMotorTorque = 2
local backboneC = physics.newJoint ( “pivot”, torsoC, pelvis, pelvis.x, pelvis.y )
backboneC.isLimitEnabled = true
backboneC:setRotationLimits ( -22.5, 22.5 )
–backboneC.isMotorEnabled = true
–backboneC.motorSpeed = 0
–backboneC.maxMotorTorque = 2
local leftHip = physics.newJoint ( “pivot”, pelvis, leftLegA, leftLegA.x, pelvis.y )
leftHip.isLimitEnabled = true
leftHip:setRotationLimits ( -45, 90 )
–leftHip.isMotorEnabled = true
–leftHip.motorSpeed = 0
–leftHip.maxMotorTorque = 2
local rightHip = physics.newJoint ( “pivot”, pelvis, rightLegA, rightLegA.x, pelvis.y )
rightHip.isLimitEnabled = true
rightHip:setRotationLimits ( -90, 45 )
–rightHip.isMotorEnabled = true
–rightHip.motorSpeed = 0
–rightHip.maxMotorTorque = 2
local leftKnee = physics.newJoint ( “pivot”, leftLegA, leftLegB, leftLegB.x, leftLegA.y + (leftLegA.height * 0.5) - 6 )
leftKnee.isLimitEnabled = true
leftKnee:setRotationLimits ( -45, 90 )
–leftKnee.isMotorEnabled = true
–leftKnee.motorSpeed = 0
–leftKnee.maxMotorTorque = 1
local rightKnee = physics.newJoint ( “pivot”, rightLegA, rightLegB, rightLegB.x, rightLegA.y + (rightLegA.height * 0.5) - 6 )
rightKnee.isLimitEnabled = true
rightKnee:setRotationLimits ( -90, 45 )
–rightKnee.isMotorEnabled = true
–rightKnee.motorSpeed = 0
–rightKnee.maxMotorTorque = 1
local leftShoulder = physics.newJoint ( “pivot”, torsoA, leftArmA, leftArmA.x, torsoA.y )
leftShoulder.isLimitEnabled = true
leftShoulder:setRotationLimits ( 0, 180 )
–leftShoulder.isMotorEnabled = true
–leftShoulder.motorSpeed = 0
–leftShoulder.maxMotorTorque = 1
local rightShoulder = physics.newJoint ( “pivot”, torsoA, rightArmA, rightArmA.x, torsoA.y )
rightShoulder.isLimitEnabled = true
rightShoulder:setRotationLimits ( -180, 0 )
–rightShoulder.isMotorEnabled = true
–rightShoulder.motorSpeed = 0
–rightShoulder.maxMotorTorque = 1
local leftElbow = physics.newJoint ( “pivot”, leftArmA, leftArmB, leftArmB.x, leftArmA.y + (leftArmA.height * 0.5) - 6 )
leftElbow.isLimitEnabled = true
leftElbow:setRotationLimits ( -45, 90 )
–leftElbow.isMotorEnabled = true
–leftElbow.motorSpeed = 0
–leftElbow.maxMotorTorque = 1
local rightElbow = physics.newJoint ( “pivot”, rightArmA, rightArmB, rightArmB.x, rightArmA.y + (rightArmA.height * 0.5) - 6 )
rightElbow.isLimitEnabled = true
rightElbow:setRotationLimits ( -90, 45 )
–rightElbow.isMotorEnabled = true
–rightElbow.motorSpeed = 0
–rightElbow.maxMotorTorque = 1
–(((((((((((((((((((((((((((((((
– ENABLE DRAGGIN RAGDOLL
–(((((((((((((((((((((((((((((((
function ragdoll:touch( event )
gameUI.dragBody( event )
end
head:addEventListener ( “touch”, ragdoll )
leftLegA:addEventListener ( “touch”, ragdoll )
leftLegB:addEventListener ( “touch”, ragdoll )
rightLegA:addEventListener ( “touch”, ragdoll )
rightLegB:addEventListener ( “touch”, ragdoll )
leftArmA:addEventListener ( “touch”, ragdoll )
leftArmB:addEventListener ( “touch”, ragdoll )
rightArmA:addEventListener ( “touch”, ragdoll )
rightArmB:addEventListener ( “touch”, ragdoll )
return ragdoll
end
[/code] [import]uid: 9592 topic_id: 17983 reply_id: 68703[/import]
That’s awesome! Did you write that?
Peach
[import]uid: 52491 topic_id: 17983 reply_id: 68712[/import]
Hej,
no i didn’t i have found it in the forum …
I have just changed it to fit my needs…
Br,
Alen
[import]uid: 9592 topic_id: 17983 reply_id: 68716[/import]
Either way very cool stuff, I hadn’t seen it before.
Thanks very much for sharing!
Peach
[import]uid: 52491 topic_id: 17983 reply_id: 68722[/import]
There was some talk on a much earlier thread. Here’s the address:
http://developer.anscamobile.com/forum/2010/10/29/new-corona-any-radgoll-examples
I’ve put the code up on Github:
https://github.com/MarkHenryC/RagDoll
Works on Mac; don’t know about Windows.
Hope it’s useful. [import]uid: 3953 topic_id: 17983 reply_id: 70298[/import]
Hi, I added this function into the ‘game’ template, and created a ragdoll with it:
local ragDoll1 = newRagdoll(50,50)
Just wondering, what do I need to do to it to change its rotation and / or apply force to it?
I tried:
ragDoll1.rotation = 20
– this changes the rotation, but its collision detection gets messed up, like the whole physics engine got rotated independent of the rest of the world
ragDoll1:applyForce(10,-20)
– this throws me an error: attempt to call method ‘applyForce’ (a nil value)
Sorry for the rookie questions!
G [import]uid: 146743 topic_id: 17983 reply_id: 113121[/import]
ragDoll1 is the group
you need to apply force on the body parts … troso or head or whatever.
Br,
Alen [import]uid: 9592 topic_id: 17983 reply_id: 113159[/import]