Function Ragdolize(mesh:TEntity)

	Global ppos:TVec3
	ppos = EntityPosition(mesh)
	
	body:Tentity=FindChild(mesh,"Bip01")
	pelvis:Tentity=FindChild(mesh,"Bip01 Pelvis")
	spine:Tentity=FindChild(mesh,"Bip01 Spine")
	spine1:Tentity=FindChild(mesh,"Bip01 Spine1")
	spine2:Tentity=FindChild(mesh,"Bip01 Spine2")
	neck:Tentity=FindChild(mesh,"Bip01 Neck")
	head:Tentity=FindChild(mesh,"Bip01 Head")
	
	
	LClavicle:Tentity=FindChild(mesh,"Bip01 L Clavicle")
	LUpperArm:Tentity=FindChild(mesh,"Bip01 L UpperArm")
	LForearm:Tentity=FindChild(mesh,"Bip01 L Forearm")
	LHand:Tentity=FindChild(mesh,"Bip01 L Hand")
	
	RClavicle:Tentity=FindChild(mesh,"Bip01 R Clavicle")
	RUpperArm:Tentity=FindChild(mesh,"Bip01 R UpperArm")
	RForearm:Tentity=FindChild(mesh,"Bip01 R Forearm")
	RHand:Tentity=FindChild(mesh,"Bip01 R Hand")
	
	
	LThigh:Tentity=FindChild(mesh,"Bip01 L Thigh")
	LCalf:Tentity=FindChild(mesh,"Bip01 L Calf")
	LFoot:Tentity=FindChild(mesh,"Bip01 L Foot")
	
	RThigh:Tentity=FindChild(mesh,"Bip01 R Thigh")
	RCalf:Tentity=FindChild(mesh,"Bip01 R Calf")
	RFoot:Tentity=FindChild(mesh,"Bip01 R Foot")
	
	
	bodyp:tbody=createbodysphere(.35)
	positionentity bodyp,entityposition(body),1
	setbodymass bodyp,1.0
	entitytype bodyp,1
	entityparent body,bodyp
	setbodymass bodyp,1
	SetBodyElasticity bodyp,0
	
	
	
	pelvisp:tbody=createbodysphere(.35)
	positionentity pelvisp,entityposition(pelvis),1
	setbodymass pelvisp,1.0
	entitytype pelvisp,1
	entityparent pelvis,pelvisp
	setbodymass pelvisp,1
	SetBodyElasticity pelvisp,0
	
	spinep:tbody=createbodysphere(.35)
	positionentity spinep,entityposition(spine),1
	setbodymass spinep,1.0
	entitytype spinep,1
	entityparent spine,spinep
	setbodymass spinep,1
	SetBodyElasticity spinep,0
	
	spinep2:tbody=createbodysphere(.35)
	positionentity spinep2,entityposition(spine2),1
	setbodymass spinep2,1.0
	entitytype spinep2,1
	entityparent spine2,spinep2
	setbodymass spinep2,1
	SetBodyElasticity spinep2,0
	
	neckp:tbody=createbodysphere(.35)
	positionentity neckp,entityposition(neck),1
	setbodymass neckp,1.0
	entitytype neckp,1
	entityparent neck,neckp
	setbodymass neckp,1
	SetBodyElasticity neckp,0
	
	headp:tbody=createbodysphere(.35)
	positionentity headp,entityposition(head),1
	setbodymass headp,1.0
	entitytype headp,1
	entityparent head,headp
	setbodymass headp,1
	SetBodyElasticity headp,0
	
	
	' LEFT HAND
	lclaviclep:tbody=createbodysphere(.35)
	positionentity lclaviclep,entityposition(lclavicle),1
	setbodymass lclaviclep,1.0
	entitytype lclaviclep,1
	entityparent lclavicle,lclaviclep
	setbodymass lclaviclep,1
	SetBodyElasticity lclaviclep,0
	
	lupperarmp:tbody=createbodysphere(.35)
	positionentity lupperarmp,entityposition(lupperarm),1
	setbodymass lupperarmp,1.0
	entitytype lupperarmp,1
	entityparent lupperarm,lupperarmp
	setbodymass lupperarmp,1
	SetBodyElasticity lupperarmp,0
	
	lforearmp:tbody=createbodysphere(.35)
	positionentity lforearmp,entityposition(lforearm),1
	setbodymass lforearmp,1.0
	entitytype lforearmp,1
	entityparent lforearm,lforearmp
	setbodymass lforearmp,1
	SetBodyElasticity lforearmp,0
	
	lhandp:tbody=createbodysphere(.35)
	positionentity lhandp,entityposition(lhand),1
	setbodymass lhandp,1.0
	entitytype lhandp,1
	entityparent lhand,lhandp
	setbodymass lhandp,1
	SetBodyElasticity lhandp,0
	
	
	' RIGHT HAND
	rclaviclep:tbody=createbodysphere(.35)
	positionentity rclaviclep,entityposition(rclavicle),1
	setbodymass rclaviclep,1.0
	entitytype rclaviclep,1
	entityparent rclavicle,rclaviclep
	setbodymass rclaviclep,1
	SetBodyElasticity rclaviclep,0
	
	rupperarmp:tbody=createbodysphere(.35)
	positionentity rupperarmp,entityposition(rupperarm),1
	setbodymass rupperarmp,1.0
	entitytype rupperarmp,1
	entityparent rupperarm,rupperarmp
	setbodymass rupperarmp,1
	SetBodyElasticity rupperarmp,0
	
	rforearmp:tbody=createbodysphere(.35)
	positionentity rforearmp,entityposition(rforearm),1
	setbodymass rforearmp,1.0
	entitytype rforearmp,1
	entityparent rforearm,rforearmp
	setbodymass rforearmp,1
	SetBodyElasticity rforearmp,0
	
	rhandp:tbody=createbodysphere(.35)
	positionentity rhandp,entityposition(rhand),1
	setbodymass rhandp,1.0
	entitytype rhandp,1
	entityparent rhand,rhandp
	setbodymass rhandp,1
	SetBodyElasticity rhandp,0
	
	
	' LEFT LEG
	LThighp:tbody=createbodysphere(.35)
	positionentity LThighp,entityposition(LThigh),1
	setbodymass LThighp,1.0
	entitytype LThighp,1
	rotateentity(LThighp, vec3(0,0,0))
	positionentity(LThighp, vec3(0,0,0))
	entityparent LThigh,LThighp
	setbodymass LThighp,1
	SetBodyElasticity LThighp,0
	
	LCalfp:tbody=createbodysphere(.35)
	positionentity LCalfp,entityposition(LCalf),1
	setbodymass LCalfp,1.0
	entitytype LCalfp,1
	rotateentity(LCalfp, vec3(0,0,0))
	positionentity(LCalfp, vec3(0,0,0))
	entityparent LCalf,LCalfp
	setbodymass LCalfp,1
	SetBodyElasticity LCalfp,0
	
	Lfootp:tbody=createbodysphere(.35)
	positionentity LCalfp,entityposition(Lfoot),1
	setbodymass Lfootp,1.0
	entitytype Lfootp,1
	rotateentity(Lfootp, vec3(0,0,0))
	positionentity(Lfootp, vec3(0,0,0))
	entityparent Lfoot,Lfootp
	setbodymass Lfootp,1
	SetBodyElasticity Lfootp,0
	
	CreateJointHinge( LThighp, LCalfp, vec3(ppos.x,ppos.y,ppos.z), vec3(0,0,1 ))
	CreateJointHinge( LCalfp, LFootp, vec3(ppos.x,ppos.y,ppos.z), vec3(0,0,1 ))

EndFunction