ArcBasicDocs
3DPhysicsArcBasic extension

ContactNZ

Z of a physics contact's normal.

ContactNZ# ( entity,index )

Parameters

entity
entity handle
index
which contact, from 1 to CountContacts

Description

Returns the Z component of a contact's normal: the direction, pointing away from the other entity, in which the body was pushed. A ball resting on the ground has a normal of 0,1,0.

Example

ContactNZ.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