getClosestCollision problem

Hi. I found problem "CollisionResults.getClosestCollision.getGeometry" returns null.

It is happen a geometry overtake another geometry.

import com.jme3.bounding.BoundingBox;
import com.jme3.collision.CollisionResult;
import com.jme3.collision.CollisionResults;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Ray;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;

public class TestClosetCollision extends SimpleApplication {

   Geometry geom1, geom2;
   Node node;
   Ray ray;
   CollisionResults results;
   public void simpleInitApp() {
      Box box = new Box(Vector3f.ZERO, Vector3f.UNIT_XYZ);
      node = new Node();
      geom1 = this.getGeometory(box, "box1", new Vector3f(5, 0, 0));
      geom2 = this.getGeometory(box, "box2", new Vector3f(10, 0, 0));
      ray = new Ray(Vector3f.ZERO, Vector3f.UNIT_X);
      results = new CollisionResults();
   public Geometry getGeometory(Mesh mesh, String name, Vector3f v) {
      Geometry geom = new Geometry(name, mesh);
      Material mat = new Material(this.getAssetManager(), "Common/MatDefs/Misc/SolidColor.j3md");
      mat.setColor("m_Color", ColorRGBA.randomColor());
      geom.setModelBound(new BoundingBox());
      return geom;
   Vector3f v  = new Vector3f(.001f, 0, 0);
   public void simpleUpdate(float tpf) {
      Vector3f local = geom2.getLocalTranslation();
      if (local.x < 0 || local.x > 10) {
         v.x *= -1;
      node.collideWith(ray, results);

      CollisionResult result = results.getClosestCollision();

   public static void main(String[] args) {
      new TestClosetCollision().start();

Thank you.

I think I might be experiencing something similar as I've been frustrated with a piece of code I've been working on for a while that I couldn't figure out for the life of me why it was returning null for the closest geometry even though there were several it should be piercing with the ray collision. Guess this might have something to do with it.

I think this might be related to this bug:

Its related to how the CollisionResults is automatically sorted on getCollision() call, so the proper geometry can't be set.

Latest svn repository code works fine ! Thank you.  :slight_smile: