I want to have objects go to other objectBs after detecting that objectA is a certain distance or length away.
Prior to that I want it to find the closest one, which I can always do by looping through each and then storing its distance in a variable and testing it each loop to see if it is lower or equal to this distance.
But what is the best or better ways of doing this in programming?
For objectFinder.IsCheckingForTarget
for objectAs
if objectA distance to objectFinder < objectFinder.maxDistCheck
Set objectFinder.UIDOfTarget to objectA.UID
Set objectFinder.DistanceToMyTarget to dist(self.X, self.Y, objectA.X, objectA.Y)
Set objectFinder.maxDistCheck to objectFinder.DistanceToMyTarget
yea and each tick I could have a const store its max distance and reset it when certain conditions are met, such as meeting with its target ((objectFinder.IsOnTarget))
but thats not the problem
the problem is I want a new condition to see that if the distance of this nearest one is over another set distance, find something else before it and go to it. I'm guessing i'll end up using my own system of state machines to manage this, how would you approach it?