Collision on android does not work properly

hi all i ve done an jme3 app for android

i created a sphere on the top right corner of the screen but using standard code for detect collision does not give me the right mesh i touch on the screen.

[java]

Vector3f origin = getCamera().getWorldCoordinates(getInputManager().getCursorPosition(), 0.0f);

Vector3f direction = getCamera().getWorldCoordinates(getInputManager().getCursorPosition(), 0.3f);

direction.subtractLocal(origin).normalizeLocal();

CollisionResults results = new CollisionResults();

Ray ray = new Ray(origin, direction);

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

String name ="";

if (results.getClosestCollision()!=null) {

name= results.getClosestCollision().getGeometry().getName();

}

<name is not equals to the name of the geometry i touch…>

[/java]

This code works properly in a standard jme3 application.

Are you sure? Maybe you expect the name of a node, you will always get the geometry leaf name.

i added sphere and sphere2 to my node pivot and pivot to rootnode.

sphere is called “sphere” and sphere2 is called “sphere2” but the previous code give me always “sphere” even if i touch sphere2



Exists an alternative way to see if i touch a geometry in android screen?

jme3 for android probably has a bug with the collision

From all experienced until now… its probably you. Can you just print the object id instead and look if they’re really the same? Like System.out.println(spatial.toString()); Collision code isn’t any different on android.

1 Like

I 've to correct my sentences.

I touch sphere in the center of the screen and the collision spatial name is right;.I touch the spatial sphere2 in the left corner of the screen and name is ‘’ (null).

If i touch the opposite corner of the screen the collision spatial name is sphere2 but the spatial is really in the opposite corner.

Looks like the code i use for fetching collision works in the opposite way.

Where is my error?Should i negate some direction?

[java] sphere2 = new Geometry(“sphere2”, mesh2);

sphere2.move(-1.3f,-2.2f,2) ;

pivot.attachChild(sphere2);

mesh = new Sphere(30, 18, 1.9f);

mesh.setTextureMode(Sphere.TextureMode.Original);

sphere = new Geometry(“sphere”, mesh);

pivot.attachChild(sphere);

rootNode.attachChild(pivot);

[/java]

Looks like i have to reverse perspective but i do not know how with that code.Please help

[java]Vector3f origin = getCamera().getWorldCoordinates(getInputManager().getCursorPosition(), 0.0f);

Vector3f direction = getCamera().getWorldCoordinates(getInputManager().getCursorPosition(), 0.3f);

direction.subtractLocal(origin).normalizeLocal();

CollisionResults results = new CollisionResults();

Ray ray = new Ray(origin, direction);

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

String name ="";

if (results.getClosestCollision()!=null) {

name= results.getClosestCollision().getGeometry().getName();

}

[/java]

i solved using trasparent spatial in the opposite side but it’s a work around i d like to be more accurate with your help

but thank u anyway

Not a signle thing is different on android concerning picking, just read the manual. Also maybe the Math for Dummies document.