Turret Targeting

Blitz3D Forums/Blitz3D Programming/Turret Targeting

Why not just have two nested for loops?

Have a local variable, smallestDistance.

For a.Unit = each Unit

     For b.Unit = each Unit

          If EntityDistance(a\mdl, b\mdl) < smallestDistance

               smallestDistance = EntityDistance(a\mdl, b\mdl)
               a\target = EntityName(b\mdl)

          Endif

     Next

Next


It's hard to write code, because I usually do things differently, but I've used this general implementation many times to great success.