Hi, could somebody please explain to me how to search an array that will find the index that contains the closest object to another object, then move to it? I have an array with 8 gameObjects (circles with 50 radius) and a single 'playerObject' that must move over the top of the nearest circle in the array and then move over the top of the next nearest circle until all circles (gameObjects) have been 'eaten'. I would like to use the Euclidean distance. One more thing the positions of the gameObjects (Array) and the playerObject is randomized at each start of the program.
So basically determine which is the closest barrier(gameObject) from the current position of the player object.
All I have so far is a loop going through the array and some pseudo-code
//newX = barriers[];
//value to move to barrier?
//Use Euclidean distance then update
//increment value to move it
//'gameObject' is the way you access the components
//of the GameObject that this component belongs to
//when a GameObjectComponent is added to a GameObject,
//the function "AddComponent" automatically assigns
//the GameObject itself to this 'gameObject' variable.
//see 'GameObject.java' for more details.
Thankyou.