Empty collision spots in mesh

Ive created a floor(using mesh),
but there are alwats few places on the mesh( not on the edges but somewhere inside) where collision dossent occur .(results.size==0)
and i cant figure out why. Maybe you can find out what im doing wrong :frowning:
Hope its not too long to help me , but i cant make it shorter if i want to show how its all done.

I believe the mesh is good , and thats my problem is somewhere in the collisions detection code (and maybe the ray building)

This is where i set up camera and build the mesh:
[java]
public void simpleInitApp() {
flyCam.setEnabled(false);
inputManager.setCursorVisible(true);
camNode=new CameraNode(โ€œCamโ€, cam);
camNode.setLocalTranslation(new Vector3f(10f,20f,15f));
camNode.lookAt(new Vector3f(10f,0f,-10f) , Vector3f.UNIT_Y);
rootNode.attachChild(camNode);
rootNode.attachChild(floor);
buildMesh();
}
[/java]

This is the buildMesh method :

[java]
private void buildMesh() {
Mesh mesh = new Mesh();
int xCount=20;
int zCount=20;
float width=1f;
int totalSquers=xCount*zCount;

    FloatBuffer vertexBuffer = BufferUtils.createVector3Buffer(4*totalSquers);
    FloatBuffer texBuffer = BufferUtils.createVector2Buffer(4*totalSquers);
    IntBuffer indexBuffer = BufferUtils.createIntBuffer(3*4*totalSquers);
    
    for (float i=0;i<xCount;i++){
        for (float j=0;j<zCount;j++){
            
            float basex=i*width;
            float basez=(-zCount+j+1);

            vertexBuffer.put(basex).put(0).put(basez);
            vertexBuffer.put(basex+width).put(0).put(basez);
            vertexBuffer.put(basex).put(0).put(basez-width);
            vertexBuffer.put(basex+width).put(0).put(basez-width);

            int[] indices = new int[] {
                    2,0,1,
                    1,3,2
            };
            for ( int k = 0; k < indices.length; k++ ) {
                indices[k] += (i*zCount + j)*4;
            }
            indexBuffer.put(indices);              
        }
    }

    mesh.setBuffer(VertexBuffer.Type.Position,3,vertexBuffer);
    mesh.setBuffer(VertexBuffer.Type.TexCoord,2,texBuffer);
    mesh.setBuffer(VertexBuffer.Type.Index,3,indexBuffer);
    mesh.setStatic();
    mesh.updateBound();
    geo = new Geometry("OurMesh", mesh);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    geo.setMaterial(mat);
    floor.attachChild(geo);           
}

[/java]

This is the update loop:
[java]
public void simpleUpdate(float tpf) {
CollisionResults results=check_for_collisions(floor);
//if mouse is outside of floor
if (results.size()==0){
System.out.println("Im in trackable plane out side the floor - " + new Date());
System.out.println(โ€œ");
}
else{
System.out.println(โ€œIm in trackable plane in side the floor - " + new Date());
System.out.println(results.getClosestCollision().getGeometry().getName()+โ€ - "+ results.getClosestCollision().getContactPoint().toString());
System.out.println("
โ€);
}
}
[/java]

And this is the check_for_collisions method ( same as shown in the tutorials)

[java]
private CollisionResults check_for_collisions(Node checked_node) {
// Reset results list.
CollisionResults results = new CollisionResults();
// Convert screen click to 3d position
//Vector2f click2d = inputManager.getCursorPosition();
Vector2f click2d = inputManager.getCursorPosition();
System.out.println(click2d);
Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone();
System.out.println(click3d);
Vector3f direction = cam.getWorldCoordinates(inputManager.getCursorPosition(), 1f).subtractLocal(click3d).normalizeLocal();
// Aim the ray from the clicked spot forwards.
Ray ray = new Ray(click3d, direction);

    // Collect intersections between ray and checked_node in results list.
    checked_node.collideWith(ray, results);
    return results;
}

[/java]

Any one ?

Please assist :slight_smile:

This is a known bug with Rays and thin surfaces iโ€™m afraid

Meaning that if ill make my floor not 2d but 3d cubes,
it will work ?

Is there any other solution to the problem ? any workaround?

Thank you for the answer :slight_smile:
you atleast gave me hope.

A Physics RayCast with Bullet may be an option. Hereโ€™s the issues out of interest:

https://code.google.com/p/jmonkeyengine/issues/detail?id=344&q=ray&colspec=ID%20Type%20Status%20Component%20Priority%20Difficulty%20Product%20Milestone%20Owner%20Summary

https://code.google.com/p/jmonkeyengine/issues/detail?id=455&q=ray&colspec=ID%20Type%20Status%20Component%20Priority%20Difficulty%20Product%20Milestone%20Owner%20Summary

Can you point me to the Physics RayCast info ?
couldnt find it anywhere .

You use it with Bullet Collision Shapes, heres a test using it:

https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/test/jme3test/bullet/TestPhysicsRayCast.java

This works slightly differently as its not an infinite Ray, and in that example is only 1 unit long