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