ArcBasicDocs

help/commands/3d_examples

EntityRagdoll.abs

79 lines of ArcBasic. Words in colour that are commands link to their help page. To run it, download ArcBasic, open the file and press F5.

Download EntityRagdoll.absAll files in this folder

EntityRagdoll.abs
; 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