ArcBasicDocs
3DPhysics RagdollsArcBasic extension

EntityRagdoll

Makes an animated model go limp and fall as a ragdoll; 0 hands it back to animation.

EntityRagdoll ( entity[,enable][,mass#] )

Parameters

entity
an animated model with bones, loaded with LoadAnimMesh
enable (optional)
True (the default) makes it a ragdoll, False hands it back to animation
mass# (optional)
the mass of the whole body. Defaults to 1

Description

Makes an animated character go limp and fall as a ragdoll: for when it is knocked down, hit by a car or thrown by an explosion. Each bone that moves part of the mesh becomes a physics body shaped to fit that part, joined to the bone above it so arms, legs and head swing naturally. The ragdoll starts from the pose the character is in, moving as fast as its character body was, and its animation stops.

The entity follows the ragdoll, so EntityX and the other position commands say where it has fallen, and moving it with PositionEntity carries the ragdoll along. ApplyImpulse and ApplyForce push the whole ragdoll, or with an offset, the part nearest that point, so a hit can strike the head or a leg. SetEntityVelocity sets the speed of every part. If the entity is a character (EntityCharacter) or other body, that body leaves the world while it is a ragdoll.

EntityRagdoll entity,False keeps the pose it fell into until you Animate it again, and brings its own body back.

Example

EntityRagdoll.absOpen in editor
; Physics ragdolls example (an ArcBasic extension); Animated characters that go limp when a ball hits them, and get back up again.; 1-4: throw a ball at a character   Space: everyone up againGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,3,-8TurnEntity camera,12,0,0light=CreateLight()RotateEntity light,50,30,0ground=CreatePlane()EntityColor ground,70,90,70EntityPhysics ground,1wall=CreateCube()ScaleEntity wall,5,.4,.3PositionEntity wall,0,.4,2.5EntityColor wall,150,150,170EntityPhysics wall,1; four characters, each with a character body for the balls to hitDim guy(3)For i=0 To 3	guy(i)=LoadAnimMesh("../../../media/kenney/mini-characters/character-male-"+Mid("abcd",i+1,1)+".glb")	ScaleEntity guy(i),3,3,3	PositionEntity guy(i),-3+i*2,0,0	EntityCharacter guy(i),.4,1.9	Animate guy(i),1,1,FindAnimSeq(guy(i),"idle")NextDim ball(3)While Not KeyHit(1)	For i=0 To 3		If KeyHit(2+i)			If ball(i) Then FreeEntity ball(i)			b=CreateSphere(12)			ScaleEntity b,.25,.25,.25			EntityColor b,255,220,60			PositionEntity b,EntityX(camera),EntityY(camera)-1,EntityZ(camera)			EntityPhysics b,2,5			; aim for the character's chest			dx#=EntityX(guy(i))-EntityX(b)			dy#=EntityY(guy(i))+1.3-EntityY(b)			dz#=EntityZ(guy(i))-EntityZ(b)			d#=Sqr(dx*dx+dy*dy+dz*dz)			SetEntityVelocity b,dx/d*20,dy/d*20+2,dz/d*20			ball(i)=b		EndIf	Next	If KeyHit(57)		For i=0 To 3			EntityRagdoll guy(i),0			PositionEntity guy(i),-3+i*2,0,0			RotateEntity guy(i),0,0,0			Animate guy(i),1,1,FindAnimSeq(guy(i),"idle")		Next	EndIf	UpdateWorld	; a character the ball hits goes limp, and takes the blow where the ball struck	For j=0 To 3		b=ball(j)		If b			For c=1 To CountContacts(b)				For i=0 To 3					If ContactEntity(b,c)=guy(i) And RagdollParts(guy(i))=0						EntityRagdoll guy(i),1,60						ApplyImpulse guy(i),EntityVelocityX(b)*5,EntityVelocityY(b)*5,EntityVelocityZ(b)*5,ContactX(b,c)-EntityX(guy(i)),ContactY(b,c)-EntityY(guy(i)),ContactZ(b,c)-EntityZ(guy(i))					EndIf				Next			Next		EndIf	Next	RenderWorld	Text 0,0,"1-4: throw a ball at a character   Space: everyone up again"	FlipWendEnd

See also