Ray casting yields no collision

This should be a standard collision bewteen a ray and a node, but for some reason it doesn’t work as expected.
I have this static factory method:

public class PieceFactory
{

    // ...static stuff referenced below...

    public static Node buildTilesNode()
    {
        final Node tilesNode = new Node();

        Spatial tile;

        for(int queue = 0; queue < Board.QUEUES; queue++)
            for(int level = 0; level < Board.LEVELS; level++)
            {
                tile = new Geometry(queue + ":" + level, UNIT_BOX);
                tile.setMaterial(new Material(ASSET_MANAGER, "Common/MatDefs/Misc/Unshaded.j3md"));
                ((Geometry) tile).getMaterial().setColor("Color", ColorRGBA.LightGray);

                tile.setLocalScale(CELL_WIDTH, CELL_HEIGHT, .0f);
                tile.setLocalTranslation(positionToTranslation(queue, level));

                tile.setUserData("position", new Position(queue, level));

                tilesNode.attachChild(tile);
            }

        return tilesNode;
    }
}

…and the buildTilesNode() method is used elsewhere this way:

public class Table
{
    public final Node tiles = PieceFactory.buildTilesNode();
    // ...
}

This is where something goes wrong:

public class Test extends AbstractAppState
{
    // ...stuff...

    private Table table = new Table();

    private Position pickTile()
    {
        final Vector2f clickSpot = inputManager.getCursorPosition();
        final Vector3f origin = camera.getWorldCoordinates(clickSpot, .0f);
        final Vector3f direction = 
            camera.getWorldCoordinates(clickSpot, 1.0f).subtract(origin).normalize();

        final Ray ray = new Ray(origin, direction);
        final CollisionResults results = new CollisionResults();

        table.tiles.collideWith(ray, results);

        if(results.size() > 0)
            return ((Spatial) results.getClosestCollision().getGeometry())
                   .getUserData("position");

        return null;
    }
}

The size of results happens to always be 0.
What am I doing wrong?

What version of JME?

It’s JME 3.0.

So, any idea? I really don’t know how to face the problem this time, everything seems to be ok but it just refuses to work lol :stuck_out_tongue: I’ve recreated the same conditions in another program and the collisions are flawlessly detected just as expected… Also, a call to table.tiles.getChildren.size() right before the ray casting returns the right amount, so there would actually be something to collide with.

Figure out what’s different between the program that works and the one that doesn’t. I don’t know what else to say other than step through the code in the debugger.

Collisions work for me.

At last, I figured it out:

tile.setLocalScale(CELL_WIDTH, CELL_HEIGHT, .0f);

The .0f value for the Z component prevented any collision to happen. Argh!

Ahhh yes. I ran into that two weeks ago. I had scaled a dome down to make a disk and collisions stopped working. Seems like a bug to me.

Are you also running 3.0?

Yes.

Some time I fixed a bug that had to do with ray collisions skipping bounding boxes of zero width in some cases. Since 3.0 is pretty old I’m pretty sure it was after that.

You all should really try upgrading to 3.1 alpha. Though in this case you might hit a completely different bug that has since been fixed in master.

Is there a timeline for 3.1 release candidate?

I’m just asking because I’m seeing a lot of “that’s been fixed in 3.1” in various threads on these forums but 3.1 is still in alpha. The interlude waiting for 3.1 to be ready is a bit of a bummer.

In the open source world, the difference between “alpha” and “released” is kind of arbitrary.

Never mind that if no one ever uses alpha then we don’t fix the bugs and it never gets any better anyway.