Here is a code example. You will have to change the name of the bones to match your model.
You may have to tweak some of the values. Create the joint vectors once and reuse for every ragdoll.
type TwistJoint
rotationVec3 as integer
limitsVec3 as integer
endtype
neckJoint as TwistJoint
L_ShoulderJoint as TwistJoint
R_ShoulderJoint as TwistJoint
hipJoint as TwistJoint
type HingeJoint
rotationVec3 as integer
minLimit as float
maxLimit as float
endtype
waistJoint as HingeJoint
kneeJoint as HingeJoint
rightElbowJoint as HingeJoint
leftElbowJoint as HingeJoint
rightWristJoint as HingeJoint
leftWristJoint as HingeJoint
Function CreateRagdollVectors()
kneeJoint.rotationVec3 = CreateVector3( 90.0, 0.0, 0.0 )
kneeJoint.minLimit = 0.0
kneeJoint.maxLimit = 120.0
rightElbowJoint.rotationVec3 = CreateVector3( -120.0, 0.0, 0.0 )
rightElbowJoint.minLimit = 0.0
rightElbowJoint.maxLimit = 130.0
leftElbowJoint.rotationVec3 = CreateVector3( 270.0, 0.0, 0.0 )
leftElbowJoint.minLimit = 0.0
leftElbowJoint.maxLimit = 130.0
waistJoint.rotationVec3 = CreateVector3( 90.0, 0.0, 0.0 )
waistJoint.minLimit = 0.0
waistJoint.maxLimit = 160.0
hipJoint.rotationVec3 = CreateVector3( 45.0, 45.0, 45.0 )
hipJoint.limitsVec3 = CreateVector3( 25.0, 25.0, 25.0 )
R_ShoulderJoint.rotationVec3 = CreateVector3( 0.0, 0.0, 0.0 )
R_ShoulderJoint.limitsVec3 = CreateVector3( 45.0,45.0,90.0 )
L_ShoulderJoint.rotationVec3 = CreateVector3( 0.0, 0.0, 0.0 )
L_ShoulderJoint.limitsVec3 = CreateVector3( 45.0,45.0,90.0 )
neckJoint.rotationVec3 = CreateVector3( -90.0, 0.0, 0.0 )
neckJoint.limitsVec3 = CreateVector3( 24.0, 11.5, 8.0 )
endfunction
Function CreateRagdollSkelton( int objID )
//**************** Create Ragdoll ***************************
//Create the ragdoll bones using the original objects bone positions then add all the original
//objects bones that will be moved by the ragdoll bone.Set collisions groups so bones won't collide with other bones.
StopObjectAnimation( objID )
Create3DPhysicsRagDoll( objID, 175.0 )
pelvis = Add3DPhysicsRagDollBone( GetObjectBoneByName( objID, "Crotch" ),
GetObjectBoneByName( objID, "Bip01_Spine" ), 10, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( pelvis, GetObjectBoneByName( objID, "Crotch" ) )
AssignTo3DPhysicsRagDollBoneObjectBone( pelvis, GetObjectBoneByName( objID, "Bip01_Pelvis" ) )
torso = Add3DPhysicsRagDollBone( GetObjectBoneByName( objID, "Bip01_Spine" ),
GetObjectBoneByName( objID, "Bip01_Head" ), 12, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( torso, GetObjectBoneByName( objID, "Bip01_Spine" ) )
AssignTo3DPhysicsRagDollBoneObjectBone( torso, GetObjectBoneByName( objID, "Bip01_Spine1" ) )
AssignTo3DPhysicsRagDollBoneObjectBone( torso, GetObjectBoneByName( objID, "Bip01_Spine2" ) )
AssignTo3DPhysicsRagDollBoneObjectBone( torso, GetObjectBoneByName( objID, "Bip01_Neck" ) )
AssignTo3DPhysicsRagDollBoneObjectBone( torso, GetObjectBoneByName( objID, "Bip01_L_Clavicle" ) )
AssignTo3DPhysicsRagDollBoneObjectBone( torso, GetObjectBoneByName( objID, "Bip01_R_Clavicle" ) )
head = Add3DPhysicsRagDollBone( GetObjectBoneByName( objID, "Bip01_Head" ),
GetObjectBoneByName( objID, "HeadTop" ), 8, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( head, GetObjectBoneByName( objID, "Bip01_Head" ) )
AssignTo3DPhysicsRagDollBoneObjectBone( head, GetObjectBoneByName( objID, "HeadTop" ) )
L_UpperArm = Add3DPhysicsRagDollBone( GetObjectBoneByName( objID, "Bip01_L_UpperArm" ),
GetObjectBoneByName( objID, "Bip01_L_Forearm" ), 6, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( L_UpperArm, GetObjectBoneByName( objID, "Bip01_L_UpperArm" ) )
L_ForeArm = Add3DPhysicsRagDollBone( GetObjectBoneByName( objID, "Bip01_L_Forearm" ),
GetObjectBoneByName( objID, "Bip01_L_Hand" ), 5, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( L_ForeArm, GetObjectBoneByName( objID, "Bip01_L_Forearm" ) )
R_UpperArm = Add3DPhysicsRagDollBone( agk::GetObjectBoneByName( objID, "Bip01_R_UpperArm" ),
GetObjectBoneByName( objID, "Bip01_R_Forearm" ), 6, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( R_UpperArm, GetObjectBoneByName( objID, "Bip01_R_UpperArm" ) )
int R_ForeArm = agk::Add3DPhysicsRagDollBone( GetObjectBoneByName( objID, "Bip01_R_Forearm" ),
GetObjectBoneByName( objID, "Bip01_R_Hand" ), 5, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( R_ForeArm, agk::GetObjectBoneByName( objID, "Bip01_R_Forearm" ) )
L_Thigh = Add3DPhysicsRagDollBone( GetObjectBoneByName( objID, "Bip01_L_Thigh" ),
GetObjectBoneByName( objID, "Bip01_L_Calf" ), 7, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( L_Thigh, GetObjectBoneByName( objID, "Bip01_L_Thigh" ) )
L_Calf = Add3DPhysicsRagDollBone( GetObjectBoneByName( objID, "Bip01_L_Calf" ),
GetObjectBoneByName( objID, "Bip01_L_Foot" ), 5, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( L_Calf, GetObjectBoneByName( objID, "Bip01_L_Calf" ) )
R_Thigh = Add3DPhysicsRagDollBone( GetObjectBoneByName( objID, "Bip01_R_Thigh" ),
GetObjectBoneByName( objID, "Bip01_R_Calf" ), 7, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( R_Thigh, GetObjectBoneByName( objID, "Bip01_R_Thigh" ) );
int R_Calf = agk::Add3DPhysicsRagDollBone( GetObjectBoneByName( objID, "Bip01_R_Calf" ),
GetObjectBoneByName( objID, "Bip01_R_Foot" ), 5, -1 )
AssignTo3DPhysicsRagDollBoneObjectBone( R_Calf, GetObjectBoneByName( objID, "Bip01_R_Calf" ) )
//Now Create Joints between ragdoll bones
Add3DPhysicsRagDollTwistJoint( torso, head, GetObjectBoneByName( objID, "Bip01_Head" ),
CreateVector3( 90.0, 0.0, 90.0 ), CreateVector3( 24.0, 11.5, 8.0 ) )
Add3DPhysicsRagDollHingeJoint( pelvis, torso, GetObjectBoneByName( objID, "Bip01_Spine" ),
waistJoint.rotationVec3, waistJoint.minLimit, waistJoint.maxLimit )
Add3DPhysicsRagDollTwistJoint( torso, L_UpperArm, GetObjectBoneByName( objID, "Bip01_L_UpperArm" ),
L_ShoulderJoint.rotationVec3, L_ShoulderJoint.limitsVec3 )
Add3DPhysicsRagDollTwistJoint( torso, R_UpperArm, GetObjectBoneByName( objID, "Bip01_R_UpperArm" ),
R_ShoulderJoint.rotationVec3, R_ShoulderJoint.limitsVec3 )
Add3DPhysicsRagDollHingeJoint( L_UpperArm, L_ForeArm, GetObjectBoneByName( objID, "Bip01_L_Forearm" ),
leftElbowJoint.rotationVec3, leftElbowJoint.minLimit, leftElbowJoint.maxLimit )
Add3DPhysicsRagDollHingeJoint( R_UpperArm, R_ForeArm, GetObjectBoneByName( objID, "Bip01_R_Forearm" ),
rightElbowJoint.rotationVec3, rightElbowJoint.minLimit, rightElbowJoint.maxLimit );
Add3DPhysicsRagDollTwistJoint( pelvis, L_Thigh, GetObjectBoneByName( objID, "Bip01_L_Thigh" ),
hipJoint.rotationVec3, hipJoint.limitsVec3 )
Add3DPhysicsRagDollTwistJoint( pelvis, R_Thigh, GetObjectBoneByName( objID, "Bip01_R_Thigh" ),
hipJoint.rotationVec3, hipJoint.limitsVec3 )
Add3DPhysicsRagDollHingeJoint( L_Thigh, L_Calf, GetObjectBoneByName( objID, "Bip01_L_Calf" ),
kneeJoint.rotationVec3, kneeJoint.minLimit, kneeJoint.maxLimit )
Add3DPhysicsRagDollHingeJoint( R_Thigh, R_Calf, GetObjectBoneByName( objID, "Bip01_R_Calf" ),
kneeJoint.rotationVec3, kneeJoint.minLimit, kneeJoint.maxLimit )
Finalize3DPhysicsRagDoll()
endfunction
The coffee is lovely dark and deep,and I have code to write before I sleep.