Make geometries come close to a specific object if distance is > 10

I’m trying to make geometries shaped like boxes come towards me, the camera when the distance is >= 10. I added 0.001 repeatedly to each of the x and z of the geometry,

add 0.001 to x, if x < camera’s x, otherwise subtract 0.001. I have the same thing for z as well. The problem is that the distance is getting larger instead of smaller, how do i fix this? Thanks in advance.

im having another problem, the stuff i posted above is fixed. My other problem is that all of the geometries eventually have the same x and z, so would i just setup a random float x and z and then add that to the previous geometries x and z values and just jeep changing the distance x and z randomly in a loop? would that work?


public void simpleUpdate() {

float boxX = box.getLocalScale().getX();

float boxZ = box.getLocalScale().getZ();

float camX = cam.getLocation().getX();

float camZ = cam.getLocation().getZ();

Random rand = new Random();

float randomX = rand.nextFloat(5);

float randomY = rand.nextFloat(5);

Vector3f sum = new Vector3f(randomX, 0, randomZ);

float camDistanceX = camX-boxX;

float camDistanceZ = camZ-boxZ;




something like this?

I fixed it my own way, but thanks for the code. I’m trying to make a simple enemy box with a 2d sprite go towards the player and kill him. The way I’m doing the layout for the enemies is really bad, because I’m not using physics collision shapes.