Problem with collisions and many moving objects

Blitz3D Forums/Blitz3D Programming/Problem with collisions and many moving objects

NobodyInParticular(Posted 2004) [#1]
I can't seem to figure out a working solution to this problem. I am making an space arcade shooter type of game that is simular to the combat in EV Nova, Star Control, and others. But I am having problems with detecting when a ship has been hit by enemy fire.

I whipped up this quick example to show what I am needing help with. Sometimes the small yellow spheres pass right thru the blue cube without registering a collision.
Graphics3D 800,600,32,2
SetBuffer BackBuffer ()
AppTitle "Test Multiple Collisions"
HidePointer

CX = 400
CY = 300

Const BulletCol = 1
Const CubeCol = 2

Type BulletTestType
	Field X#
	Field Y#
	Field Z#
	Field Speed#
	Field Entity
End Type

Camera=CreateCamera()
CameraZoom Camera,1.6
Light=CreateLight()
PositionEntity Camera,0,13,-18

BigCube = CreateCube()
EntityColor BigCube,0,0,255
ScaleEntity BigCube,2,2,2
PointEntity camera,bigcube
EntityType BigCube,CubeCol

LittleCube = CreateCube()
EntityColor LittleCube,255,0,0
MoveEntity LittleCube,0,0,30
PointEntity LittleCube,BigCube
SeedRnd (MilliSecs ())
For xxx = 1 To 12
	Bullet.BulletTestType = New BulletTestType
	Bullet\x# = EntityX(LittleCube)
	Bullet\y# = EntityY(LittleCube)
	Bullet\z# = EntityZ(LittleCube)
	Bullet\Speed# = Rnd(.05,1.5)
	Bullet\Entity = CreateSphere(8)
	EntityType Bullet\Entity,BulletCol
	EntityColor Bullet\Entity,255,255,0
	ScaleEntity Bullet\Entity,.2,.2,.2
	PositionEntity Bullet\Entity,Bullet\x#,Bullet\y#,Bullet\z#
	RotateEntity Bullet\Entity,EntityPitch (LittleCube),EntityYaw(LittleCube),EntityRoll(LittleCube)
Next 

CameraTestMode = True 
LCY = EntityYaw(littlecube)
LCYI = 1
MoveMouse cx,cy
Collisions BulletCol,Cubecol,1,1
While Not KeyHit(1)
	TurnEntity bigcube,0,1,0
	For Bullet.BulletTestType = Each BulletTestType		
		MoveEntity Bullet\Entity,0,0,Bullet\Speed#
		If EntityDistance(Bullet\Entity,LittleCube) > 45 Then
			PositionEntity Bullet\Entity,Bullet\x#,Bullet\y#,Bullet\z#
			RotateEntity Bullet\Entity,EntityPitch (LittleCube),EntityYaw(LittleCube),EntityRoll(LittleCube)
			Bullet\Speed# = Rnd(.05,1.5)
			missed = missed + 1
		End If
		If EntityCollided (Bullet\Entity,CubeCol) Then
			PositionEntity Bullet\Entity,Bullet\x#,Bullet\y#,Bullet\z#
			RotateEntity Bullet\Entity,EntityPitch (LittleCube),EntityYaw(LittleCube),EntityRoll(LittleCube)
			Bullet\Speed# = Rnd(.05,1.5)
			damage = damage + 1
		End If 
	Next
	LCY = LCY + LCYI
	If LCY > 190 Then LCYI = -1
	If LCY < 170 Then LCYI = 1
	RotateEntity LittleCube,EntityPitch(Littlecube),LCY,EntityRoll(LittleCube)
.Camera_Movement	
	If CameraTestMode = True Then
		If KeyDown(17) Then
			MoveEntity Camera,0,0,.2
		End If
		If KeyDown(31) Then
			MoveEntity Camera,0,0,-.2
		End If
		If KeyDown(30) Then
			MoveEntity camera,-.2,0,0	
		End If
		If KeyDown(32) Then
			MoveEntity camera,.2,0,0
		End If	
		TurnEntity camera,MouseYSpeed()/10.0,-MouseXSpeed()/10.0,0
		MoveMouse CX,CY
		TranslateEntity camera,0,MouseZSpeed()*2.0,0
		TurnEntity camera,0,0,-EntityRoll(camera)
	End If	
	UpdateWorld
	RenderWorld
	Text 0,0,"Hit = " + Damage
	Text 0,10,"Missed = " + Missed
	Flip 
Wend

End 



Hujiklo(Posted 2004) [#2]
It's Blitz I think - it only registers collisions automatically when only one of the objects is moving. Somebody I think mentioned a code work-around but I never saw it.

However - you can buy Nuclearglory's collision dll like I did which works fantastic - it was about $15 -20 I think.

Not an ideal solution considering you've already bought Blitz. :(


RiverRatt(Posted 2004) [#3]
Well I don't know about this...
" it only registers collisions automatically when only one of the objects is moving. "
but if you use an entitybox method it works.



NobodyInParticular(Posted 2004) [#4]
Thanks for the help RiverRatt, it never even occurred to me to try anything besides ellipsoid-to-ellipsoid collision because that is what I always used before, but using the Entitybox method worked great in the game, it looks like it solved the problem completly...

I have downloaded the demo of Nuclearglory's collision .DLL, but I haven't gotten around to trying it out yet...


RiverRatt(Posted 2004) [#5]
Your welcome glad I could help. I think ellipsoid-to-ellipsoid was ment mostly for collition between moving objects and your leval (walls and stuff).