Forsooth! My Missile Won't Work

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

Your code is a bit of a mess but I see the problem.

As you are using the 'foe' variable to iterate through the type list to apply gravity, 'foe' will be set to null at the end of the loop.

See example :

For foe.target=Each target
  TranslateEntity foe\shape,0,-2,0
  debuglog str$(foe)
Next
debuglog str$(foe)  ; <---- foe will be [NULL]


Don't use the same variable for the missiles target, use a global variable:

global MissileTarget.Target


and set it to one of the existing targets, once they are created :


MissileTarget = GetNearestTarget( Cam )

function GetNearestTarget.Target( Source )

  local Found.target = null

  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


Then, instead of using foe\shape for the missile targetting, use MissileTarget\Shape.

Stevie