Finding the closest target in an array
📦 Misc•Updated 2 days ago•1 views
Keep a `closesttarget` variable, iterate through the array, and for each entry compare its distance to the current closest: if current distance < closest target…
How would you make the target the closest target?
Keep a `closesttarget` variable, iterate through the array, and for each entry compare its distance to the current closest:
if current distance < closest target distance then closest target = current thing
At the end of the loop the variable holds the closest object. (The radar's built-in distance output exists but was described as unreliable because it does not start unless targets are very close.)