Ive hit a road block even though I think the solution is probably staring me in the face.
I have 5 static objects and 1 objects which moves (ill call this A).
When the program starts I need A to move to the closest object. Once its there I need it to move to the next closest one, then the next closest one etc. Once it has moved to an object it needs to ignore it for the rest of the run. Once it has moved through all 5 objects the program ends.
The way I have done it is made an array and find the distance to all the balls and store these values in an array.
Next I have made a 2nd array to store the sorted distances.
Then I have a for loop with this in it
Once this executes, say it gets to i = 3 and that is equal to the smallest distance it then sets 3 as the value for which object I want to move to.
if(eculDist[i] == eculDistSort)
Now my program currently moves A to the closest object but once its there I have no idea how to get it to then move again to the next closest one.
I have used
to see whats happening and the numbers are constantly been updated as A moves closer to the object.
Sorry for the wall of text.
Thanks for any help.
Re: Array help
Well, you can do a couple different things. Either make sure you only create that array once instead of updating it constantly, or you can update it constantly but keep track of which Objects you've already visited (either as a part of the Object itself or in a separate data structure). Which one you go with is dependent upon exactly what you want the program to do.