the code work perfectly when i have one creature but when i have more than one creature, they all go to the closest water source.
So i have three creatures and three water sources, the code find the closest water source for one creature (the creature with the shortest distant between that creature and a water source) and then all the creatures go to that water source.
i have a final question just for understand properly : when i put my PVector target in the if statement like you said i got an error in my c1m.arrive(target) saying “target cannot be resolved to a variable”
whats the problem ?
its work without that change and i think its not a problem but im not sure
It is because you declare the variable inside your if statement so it exists only here (If I’m not saying any non sense scope of variables are inside the block they are declared in).
What you should do is actualy declare your variable in the first for loop and then only update the x and y parameter lke so: