ArcBasicDocs
3DPhysicsArcBasic extension

CountContacts

Number of contacts a physics body had during the last UpdateWorld.

CountContacts ( entity )

Parameters

entity
entity handle

Description

Returns how many places a physics body touched other bodies during the last UpdateWorld. Use ContactEntity, ContactX and the other contact commands to find out more about each one.

A body that has come to rest is put to sleep and reports no contacts until something moves it. Static bodies report the contacts of the bodies that hit them.

Example

CountContacts.absOpen in editor
; Physics contacts example (an ArcBasic extension); Balls rain onto blocks; a block lights up when it is hit hardGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,8,-14TurnEntity camera,25,0,0light=CreateLight()RotateEntity light,50,30,0ground=CreatePlane()EntityColor ground,60,60,60EntityPhysics ground,1Dim block(4)For i=0 To 4	block(i)=CreateCube()	PositionEntity block(i),i*2.5-5,1,0	EntityPhysics block(i),1Nextmarker=CreateSphere(6)ScaleEntity marker,.15,.15,.15EntityColor marker,255,0,0While Not KeyHit(1)	If Rand(0,10)=0 And balls<150		balls=balls+1		ball=CreateSphere(8)		ScaleEntity ball,.3,.3,.3		PositionEntity ball,Rnd(-6,6),8,Rnd(-.5,.5)		EntityPhysics ball,2		EntityBounce ball,.5	EndIf	UpdateWorld	For i=0 To 4		EntityColor block(i),120,120,160		For c=1 To CountContacts(block(i))			If ContactImpulse(block(i),c)>1				EntityColor block(i),255,220,80				; show where it was hit				PositionEntity marker,ContactX(block(i),c),ContactY(block(i),c),ContactZ(block(i),c)				; ContactEntity is the ball that hit it: turn it red				EntityColor ContactEntity(block(i),c),255,60,60				; the normal points away from the ball, so down for a hit on top				If ContactNY(block(i),c)<-.5 Then hits=hits+1			EndIf		Next	Next	RenderWorld	Text 0,0,"Hits on top of the blocks: "+hits	FlipWendEnd

See also