Collisions not working

Blitz3D Forums/Blitz3D Programming/Collisions not working

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

EntityType is set correctly (I am sure)

bullets=Type 3
planets,stars and asteroids =Type 7,8,9
here is some code that I have taken from my program:


; Fire Bullet
.Bullet_Fire

;limit fire-rate
If (MilliSecs()-fire_rate)<bullet_recharge Then Return

PlaySound primarysound
fire_rate=MilliSecs()

NewBullet.Ship_Bullet = New Ship_Bullet
Newbullet\x#=EntityX#(ship)
Newbullet\y#=EntityY#(ship)
Newbullet\z#=EntityZ#(ship)
Newbullet\range=gun_range
Newbullet\bullet_sprite=CopyEntity (bullet)

EntityType newbullet\bullet_sprite,3

EntityRadius Newbullet\bullet_sprite,0.4,0.4
EntityPickMode Newbullet\bullet_sprite,3,0 
PositionEntity newbullet\bullet_sprite,newbullet\x#,newbullet\y#,newbullet\z# 
EntityType Newbullet\bullet_sprite,3 

shipp#=EntityPitch#(ship)
shipy#=EntityYaw#(ship)
shipr#=EntityRoll#(ship)
RotateEntity newbullet\bullet_sprite,shipp,shipy,shipr

EntityRadius newbullet\bullet_sprite,10,10
EntityPickMode newbullet\bullet_sprite,1

Return

;Bullet Collisions and movement

.Bullet_Coll

For ThisBullet.Ship_Bullet = Each Ship_Bullet

If thisbullet\range<1 Then FreeEntity thisbullet\bullet_sprite:Delete thisbullet:Exit

MoveEntity thisbullet\bullet_sprite,0,0,bullet_speed
Thisbullet\range=thisbullet\range-(bullet_speed) 

If CountCollisions(thisbullet\bullet_sprite)>0
Gosub Bullet_Collide
Exit
EndIf
Next

Return


.Bullet_collide

;Check collision with Stars

If EntityCollided (thisbullet\bullet_sprite,8)>0
Gosub create_new_impact
Return
EndIf

;Check collision with Planets

If EntityCollided (thisbullet\bullet_sprite,9)>0
Gosub create_new_impact
Return
EndIf


;Check collision with Roids

If EntityCollided (thisbullet\bullet_sprite,7)>0
Gosub create_new_impact
Return
EndIf

; (Create new impact)







.create_new_impact

NewImpact.Impact_explosion = New impact_explosion
Newimpact\sprite=CreateSprite()
ScaleSprite newimpact\Sprite,10,10
PaintEntity newimpact\sprite,impact_brush
newimpact\PosX=EntityX(thisbullet\bullet_sprite)
newimpact\PosY=EntityY(thisbullet\bullet_sprite)
newimpact\PosZ=EntityZ(thisbullet\bullet_sprite)
newimpact\AnimFrame=0
FreeEntity thisbullet\bullet_sprite
Delete thisbullet
Return



.impact_Anims

For Impacts.impact_explosion=Each Impact_Explosion
impacts\AnimFrame=(impacts\AnimFrame)+1
If impacts\AnimFrame>6 
FreeEntity impacts\Sprite 
Delete impacts 
Exit
EndIf
BrushTexture impact_brush,impact_texture,impacts\Animframe
PaintEntity impacts\Sprite,impact_brush
Next
Return


Global sunlight=CreateLight(2)
LightRange sunlight,10000
LightConeAngles sunlight,0,359

sectorfile=OpenFile("Libraries\Sectors"+sector$+"\Objects.DAT")
ambient_red=ReadLine (SectorFile)
ambient_green=ReadLine (SectorFile)
ambient_blue=ReadLine (SectorFile)

LightColor sunlight,ambient_red+15,ambient_green+10,ambient_blue+5

AmbientLight ambient_red,ambient_green,ambient_blue

Faction$=ReadLine(sectorFile)

max_stars=ReadLine (SectorFile)

For sf = 1 To max_stars 

setup_star.sector_star = New sector_star 
setup_star\name$=ReadLine (SectorFile)
setup_star\class$=ReadLine (SectorFile)
setup_star\PosX=ReadLine (SectorFile)
setup_star\PosY=ReadLine (SectorFile)
setup_star\PosZ=ReadLine (SectorFile)
setup_star\ScaleX=ReadLine (SectorFile)
setup_star\ScaleZ=ReadLine (SectorFile)
setup_star\Sprite=LoadSprite("Visual\Sectors"+sector$+"\S"+sf+".bmp")
SpriteViewMode setup_star\sprite,1
ScaleSprite setup_star\sprite,setup_star\ScaleX,setup_star\ScaleZ
PositionEntity setup_star\sprite,setup_star\posX,setup_star\PosY,setup_star\PosZ
PositionEntity sunlight,setup_star\posX,setup_star\PosY,setup_star\PosZ

NameEntity setup_star\Sprite,"Star"

EntityType setup_star\sprite,8

EntityRadius setup_star\Sprite,setup_star\ScaleX,setup_star\ScaleZ
EntityPickMode setup_star\sprite,1

 Next 



max_planets=ReadLine (SectorFile)

For pf = 1 To max_planets 

setup_planet.sector_planet = New sector_planet 
setup_planet\name$=ReadLine (SectorFile)
setup_planet\Class$=ReadLine (SectorFile)
setup_planet\PosX=ReadLine (SectorFile)
setup_planet\PosY=ReadLine (SectorFile)
setup_planet\PosZ=ReadLine (SectorFile)
setup_planet\ScaleX=ReadLine (SectorFile)
setup_planet\ScaleY=ReadLine (SectorFile)
setup_planet\ScaleZ=ReadLine (SectorFile)
ringed=ReadLine (sectorfile)

setup_planet\Texture=LoadTexture("Visual\Sectors"+sector$+"\P"+pf+"Text.jpg",9)

setup_planet\mesh=CreateSphere(50)

PositionEntity setup_planet\mesh,setup_planet\posX,setup_planet\posY,setup_planet\posZ
EntityTexture setup_planet\mesh,setup_planet\texture
EntityShininess setup_planet\mesh,0.4
ScaleMesh setup_planet\mesh,setup_planet\scaleX,setup_planet\scaleY,setup_planet\scaleZ

If ringed=1
setup_planet\ring_sprite=LoadSprite("Visual\Sectors"+sector$+"\P"+pf+"Ring.jpg")
SpriteViewMode setup_planet\ring_sprite,2
EntityFX setup_planet\ring_sprite,16
EntityAlpha setup_planet\ring_sprite,0.9
ScaleSprite setup_planet\ring_sprite,setup_planet\scaleX*2,setup_planet\ScaleZ*4
PositionEntity setup_planet\ring_sprite,setup_planet\posX,setup_planet\posY,setup_planet\posZ
TurnEntity setup_planet\ring_sprite,90,0,0
EntityParent setup_planet\ring_sprite,setup_planet\mesh
EndIf

atmosphere=ReadLine (SectorFile)

If atmosphere=1
setup_planet\atmos_sprite=LoadSprite("Visual\Images\Jet.jpg",11)
EntityAlpha setup_planet\atmos_sprite,0.8
EntityFX setup_planet\atmos_sprite,29
SpriteViewMode setup_planet\atmos_sprite,3
ScaleSprite setup_planet\atmos_sprite,setup_planet\scaleX*1.5,setup_planet\ScaleZ*1.5
PositionEntity setup_planet\atmos_sprite,setup_planet\posX,setup_planet\posY,setup_planet\posZ
EntityParent setup_planet\atmos_sprite,setup_planet\mesh
EndIf

NameEntity setup_planet\Mesh,"Planet"

EntityType setup_planet\mesh,9

EntityRadius setup_planet\mesh,setup_planet\ScaleX,setup_planet\ScaleZ
EntityPickMode setup_planet\mesh,1

Next


max_roids=ReadLine (SectorFile)

For rf = 1 To max_roids

setup_roid.sector_roid=New sector_roid

composition=50
setup_roid\ice=Rnd(0,70)
composition=composition-(setup_roid\ice)
setup_roid\construction_minerals=Rnd(0,composition)
composition=composition-(setup_roid\construction_minerals)
setup_roid\precious_metals=Rnd(0,composition)
composition=composition-(setup_roid\precious_metals)
setup_roid\hydrocarbons=Rnd(0,composition)
composition=composition-(setup_roid\hydrocarbons)
setup_roid\radioactives=Rnd(0,composition)
composition=composition-(setup_roid\radioactives)
setup_roid\debris=composition+30
roid_seg=Rand(3,9)
setup_roid\mesh=CreateSphere(roid_seg)
roidtxt$=Rand(1,4)
setup_roid\texture=LoadTexture("Visual\3D\roid"+roidtxt$+"txt.bmp")

setup_roid\PosX=Rnd(-50000,50000)
setup_roid\PosY=Rnd(-10000,10000)
setup_roid\PosZ=Rnd(-50000,50000)

PositionEntity setup_roid\mesh,setup_roid\posX,setup_roid\PosY,setup_roid\PosZ

scalerX#=Rnd(1,15)
scalerY#=Rnd(1,15)
scalerZ#=Rnd(1,15)
ScaleEntity setup_roid\mesh,scalerX#,scalerY#,scalerZ#

EntityType setup_roid\mesh,7

EntityRadius setup_roid\mesh,ScalerX,ScalerZ
EntityPickMode setup_roid\mesh,1

EntityTexture setup_roid\mesh,setup_roid\texture

setup_roid\name$="Asteroid "+rf+(setup_roid\ice+setup_roid\posX)

NameEntity setup_roid\mesh,"Asteroid"

Next



max_objects=ReadLine (SectorFile)

For bf=1 To max_objects

setup_object.sector_object=New sector_object

setup_object\name$=ReadLine (SectorFile)
setup_object\class$=ReadLine (SectorFile)
setup_object\scaleX=ReadLine (SectorFile)
setup_object\scaleY=ReadLine (SectorFile)
setup_object\ScaleZ=ReadLine (SectorFile)
setup_object\PosX=ReadLine (SectorFile)
setup_object\PosY=ReadLine (SectorFile)
setup_object\PosZ=ReadLine (SectorFile)
setup_object\mesh=LoadMesh("Visual\3d"+setup_object\class$+".b3d")
setup_object\texture=LoadTexture("Visual\3d"+setup_object\class$+"txt.bmp")
setup_object\RotX#=ReadLine (SectorFile)
setup_object\RotY#=ReadLine (SectorFile)
setup_object\RotZ#=ReadLine (SectorFile)
setup_object\Shield=ReadLine (SectorFile)
setup_object\Hull=ReadLine (SectorFile)
setup_object\Friend_or_foe=ReadLine (SectorFile)
setup_object\Dock_Here=ReadLine (SectorFile)
PositionEntity setup_object\mesh,setup_object\posX,setup_object\PosY,setup_object\PosZ
ScaleEntity setup_object\mesh,setup_object\scaleX,setup_object\scaleY,setup_object\scaleZ

NameEntity setup_object\mesh,"Construction"

EntityType setup_object\mesh,10

EntityTexture setup_object\mesh,setup_object\texture

EntityRadius setup_object\mesh,ScaleX,ScaleZ
EntityPickMode setup_object\mesh,1


 Next

CloseFile sectorfile

skyboxt=LoadTexture("Visual\Sectors"+sector$+"\box.bmp",11)
skybox1=CreateSphere(30)
FlipMesh skybox1
EntityTexture skybox1,skyboxt
ScaleEntity skybox1,15,15,15
EntityOrder skybox1,1
EntityAlpha skybox1,0.5


For collision_value=8 To 11

For check_roid_Collisions.sector_roid=Each sector_roid

If EntityCollided (check_roid_Collisions\mesh,11) >0
FreeEntity check_roid_Collisions\mesh
Delete check_roid_Collisions
EndIf

Next

Next