Get Distance?

Hello I have this method

[java]protected Geometry makeCube(String name, float x, float y, float z) {





Box box = new Box(new Vector3f(x, y, z), 1 ,1 ,1);

cube = new Geometry(name, box);

Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

mat1.setColor("Color", ColorRGBA.Blue);

cube.setMaterial(mat1);

return cube;

}[/java]



my game is first person. How can i get the distance between me and the cube?

[java]

cube.getWorldTranslation().distance(cam.getLocation());

[/java]

Just out of head, but try that one :slight_smile:

thx i will try that! is there any way to decrease the distance that the Ray has?

While valid, your mesh is offset from the origin, so it won’t be an accurate distance. I suggest setting it to Vector3f.Zero (check out the other Box constructors) and then moving your cube

@wezrule, ah I stand corrected. I did not notice the mesh offset :stuck_out_tongue:

@lahitiris, I do not think you can limit the ray length…

thats fine, I seen it so many times in people’s posts, that whenever I see someone use a Box it’s the first thing i look for :slight_smile:

@wezrule said:
thats fine, I seen it so many times in people's posts, that whenever I see someone use a Box it's the first thing i look for :)


It's so often a mistake that I almost regret that JME's box even has that construtor. :P