Forsooth! My Missile Won't Work

Blitz3D Forums/Blitz3D Beginners Area/Forsooth! My Missile Won't Work

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.

I got nothing from the debuglog other than the fact that the \shape exists for them all.

No offence Ace but I think you should start with something simpler, or at least learn a bit more about how to use types properly.

I did mean variable, but you can only declare a global variable once in your code. I see nowhere in your code which handles missiles once space is pressed? At the moment you have to continually hold space to align and move the missile. Surely this isn't how you intend for this to work?

Anyway, this is what I meant from my previous post :

Graphics3D 1024,764
SetBuffer BackBuffer()

;Types
Const type_player=1
Const type_terrain=2
Const type_missile=3
Const type_target=4

;The camera
Global cam=CreateCamera()
ScaleEntity cam,1,1,1
PositionEntity cam,0,0,0
EntityType cam,type_player
EntityRadius cam,5

;The enviroment
.enviroment
Global ground=LoadTerrain("Canyon1.bmp")
ScaleEntity ground,5,300,5
PositionEntity ground,-500,-200,-500
tex=LoadTexture("Desert Sand.jpg")
ScaleTexture tex,50,50
EntityTexture ground,tex
EntityType ground,type_terrain
TerrainShading ground,1
TerrainDetail ground,10000

.gunz
Global gun=LoadMesh("Pistol.3ds")
PositionEntity gun,.25,gunbob#,recoil#
ScaleEntity gun,.05,.05,.05
RotateEntity gun,0,-90,0
tex3=LoadTexture("Metal 3.jpg")
EntityTexture gun,tex3
EntityParent gun,cam
EntityType gun,type_player
EntityRadius gun,.005

;The missile
missile=CreateCone()
PositionEntity missile,EntityX(cam,1),EntityY(cam,1),EntityZ(cam,1)
RotateEntity missile,90,0,0
ScaleEntity missile,.5,1,.5
EntityParent missile,cam

;The targets
.targets
Type target
     Field count
     Field shape
     Field health
End Type

;SG
Global MissileTarget.target

Global l=LoadTexture("target.jpg")
For x=1 To 5
     For z=1 To 5
          foe.target=New target
          foe\count=25
          foe\health=3
          foe\shape=CreateCube()
          ScaleEntity foe\shape,2,2,2
          PositionEntity foe\shape,Rand(-450,790)+x*5,60,Rand(-600,750)+z*5
          EntityTexture foe\shape,l
          EntityType foe\shape,type_target
          EntityRadius foe\shape,5,5
          NameEntity foe\shape,Handle(foe)
     Next
Next

;Camera look
Function CurveValue#(current#,destination#,curve)

	current#=current#+((destination#-current#)/curve)
	
	Return current#

End Function

;How far the camera can see
cam_range=10000

;Collision method & respons
Collisions type_player,type_terrain,2,2
Collisions type_missile,type_terrain,2,1
Collisions type_target,type_terrain,2,1
Collisions type_missile,type_target,2,1

.game_loop
While Not KeyDown(1)

;How near the camera can see
CameraRange cam,.1,cam_range

;Controls
If KeyDown(200)=True Then MoveEntity cam,0,0,.3
If KeyDown(205)=True Then MoveEntity cam,.3,0,0
If KeyDown(203)=True Then MoveEntity cam,-.3,0,0
If KeyDown(208)=True Then MoveEntity cam,0,0,-0.3

;More camera look
mxs#=MouseXSpeed()*.3                          
mys#=MouseYSpeed()*.3                          
                                               
dest_xangle#=dest_xangle#+mys#                 
dest_yangle#=dest_yangle#-mxs#                 
                                              
xangle#=CurveValue#(xangle#,dest_xangle#,3)   
yangle#=CurveValue#(yangle#,dest_yangle#,3)   
                                               
RotateEntity cam,xangle#,yangle#,0            
                                                   
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2

;Firing bullets
If MouseHit(1) And reload=0
     EntityParent ammo\shape,gun
     PositionEntity ammo\shape,1,-7,10
     RotateEntity ammo\shape,0,90,0
     ShowEntity ammo\shape
     EntityParent ammo\shape,0
     bamchn=PlaySound(SOUNDbam)
     ChannelVolume bamchn,.5
     ammo\count=ammo\count-1
EndIf

If KeyDown(57) Then 

	MissileTarget = GetNearestTarget( cam )

	MoveEntity missile,0,1,0
	EntityParent missile,0

	;get vector to target
	Dx# = EntityX( MissileTarget\shape ) - EntityX( missile )
	Dy# = EntityY( MissileTarget\shape ) - EntityY( missile )
	Dz# = EntityZ( MissileTarget\shape ) - EntityZ( missile )
    ;align missle to target vector
	AlignToVector missile, Dx#, Dy#, Dz#, 2, .09;.05 

EndIf

;For t.target=Each target
;DebugLog Str$(t)
;Next

bulletpath(ammo.bullet)

;Gravity
TranslateEntity cam,0,-.35,0
For foe.target=Each target
TranslateEntity foe\shape,0,-2,0
Next

;Acceleration/Jump
If KeyHit(54)=True And CountCollisions(cam)=True Then 
     acceleration#=1
     jumpchn=PlaySound(jump)
     ChannelVolume jumpchn,.2
EndIf
If Not KeyHit(54)=True Then acceleration#=acceleration#-.008
If acceleration#<-.1 Then acceleration#=-.1
TranslateEntity cam,0,acceleration#,0

;Checking for collisions
UpdateWorld

RenderWorld

;I preformed Flip elsewhere in my code

Wend

;Some of this is other stuff
;Freeing Fonts and Stuff
FreeFont hudfont
FreeSound SOUNDbam
FreeSound jump
FreeSound die
FreeSound thrust
FreeImage ch
FreeTexture l
FreeTexture tex
FreeTexture tex2
FreeTexture tex3
FreeTexture tex4

End

Function bulletpath(ammo.bullet)
     MoveEntity ammo\shape,.26,-.15,15
     If CountCollisions(ammo\shape)=True Then HideEntity ammo\shape
End Function

Function GetNearestTarget.Target( Source )

  Local Found.target

  MinDistance# = 100000

  For t.target = Each target
     
    Distance# = EntityDistance( Source , t\Shape )

    If Distance < MinDistance
       MinDistance = Distance
       Found = t
    EndIf

  Next

  Return found

End Function


If you need any further help can I suggest you make a version of your code which does not require external media. You are more likely to get help that way.

Stevie