Collision problem

Blitz3D Forums/Blitz3D Programming/Collision problem


and checked as:

EntityCollided(Shot, EnemyType)



Leaving the whole two-object-types-moving-at-once problem to one side for the moment, if that's all you're doing when looking for collisions then it's not enough. In fact it's the wrong command entirely - see my example below (EntityCollided not used once).

Graphics3D 640,480,0,0
SetBuffer BackBuffer()

SeedRnd MilliSecs()

cam=CreateCamera()
PositionEntity cam,0,10,-20

ground=CreateCube()
ScaleEntity ground,50,.1,50
EntityType ground,1
sineBase=0

PointEntity cam,ground

Type ball
	Field velocity#
	Field model
End Type
ballTemplate=CreateSphere(8)
For i=1 To 100
	currentBall.ball=New ball
	currentBall\velocity=-Rnd(.01,.1)
	currentBall\model=CopyEntity(ballTemplate)
	EntityColor currentBall\model,Rand(100,255),Rand(100,255),Rand(100,255)
	PositionEntity currentBall\model,Rnd(-10,10),10,Rnd(-10,10)
	EntityType currentBall\model,2
Next
FreeEntity ballTemplate

Collisions 2,1,2,1

While Not KeyDown(1)
	For currentBall=Each ball
		TranslateEntity currentBall\model,0,currentBall\velocity,0
		currentBall\velocity=currentBall\velocity-.1
	Next
	
	UpdateWorld	


	For currentBall=Each ball
		numberOfCollisions=CountCollisions(currentBall\model)
		If numberOfCollisions>0
			For i=1 To numberOfCollisions
				If GetEntityType(CollisionEntity(currentBall\model,i))=1
					currentBall\velocity=1
				EndIf
			Next
		EndIf
	Next

RenderWorld
Flip
Wend


As you can see, you have to iterate through all the collisions for each object (of the entitytype that leads in the collisions command), then you can decide what to do based on the entitytype of the collided entity for each one of those collisions.

Edit: Whoops, just noticed jfk EO-11110 totally beat me to most of that and that I'd misread him with my first edit. But you have a working example now.