Collision does not work with box

hi all i added a box to rootnode

and i used collision to know if my pointer touch the box but i have collision outside my box :


Box box = new Box(new Vector3f(0, -3, 0), 6f, 1f, 1f);

Geometry back = new Geometry(“galaxy”, box);



and for collision

[java] Vector3f origin = getCamera().getWorldCoordinates(

getInputManager().getCursorPosition(), 0.0f);

Vector3f direction = getCamera().getWorldCoordinates(

getInputManager().getCursorPosition(), 0.3f);


Ray ray = new Ray(origin, direction);

CollisionResults results = new CollisionResults();

int collisionSphere = box.collideWith(ray, results);

if (collisionSphere > 0) {

System.out.println(‘Box touched’);



so with that code i ve got ‘Box touched’ outside the box.Where 's my error?

You dont check the collision results

if i do [java] results.getClosestCollision().getGeometry().getName()[/java] this is not the box i touch with the pointer but another one

something wrong …

with sphere it works.With box it does not

my target is to know if the mouse pointer collide with a box.

Could u believe that with that code it does not work?!

[java]results.getClosestCollision().getGeometry().getName()[/java] return me not the box name i touch.The region where i get ‘Box touched’ is completelly wrong .Another zone

Have you got a sky box?

Sometimes collision result is messed up because the sky box is in the way but you can’t see it.

If you got one, do that sky.setLocalScale(1000); in your simpleInit and test again.

@nehon that cant happen because he has : box.collideWith

if he had rootNode.collideWith it may be a problem.

@dilembo i am using the same code in my game and it works ( i tried with a quad). The only difference i have is :


scene.getCollidables().collideWith(ray, results);

if (results.size() > 0)




I am 99% sure that the error is because you use the crappy jme’s box constructor. Try this :


/**Lower left corner is at (0,0,0) and top right corner is at (x,y,z)*/

public static Box createLowerLeftBox(float x, float y, float z)


return new Box(new Vector3f(x / 2f, y / 2f, z / 2f), x / 2f, y / 2f, z / 2f);



Exists a craapy jme’s box constructor?

Actually it is a box in a android phone screen could be that the reason?

I have collision to the box not when i touch the box.Quite strange.I ll post this to android jme3 forum

i tried to create a jme3 app and it works resizing properly the box.It’s a problem for android forum thanks anyway