I don’t know if it’s on purpose or if it’s a bug, but if you try to do a collision check between a Quad and a Ray (with the ray pointing to the quad), the ray will always collide, regardless of the value of ray.limit.
If you want to test it, try:
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(10f);
cam.setLocation(new Vector3f(2.5f, 2.5f, 10));
cam.lookAt(new Vector3f(2.5f, 2.5f, 0), Vector3f.UNIT_Y);
Node scenario = new Node("Scenario");
rootNode.attachChild(scenario);
Geometry geoQuad = new Geometry("GeoQuad", new Quad(5, 5));
Material matQuad = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matQuad.setColor("Color", ColorRGBA.Blue);
geoQuad.setMaterial(matQuad);
scenario.attachChild(geoQuad);
inputManager.addMapping("Check collision", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("Check collision") && !isPressed) {
CollisionResults results = new CollisionResults();
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
ray.limit = 1;//This value makes no difference
scenario.collideWith(ray, results);
for (int i = 0; i < results.size(); i++) {
System.out.println("Collided with: "+results.getCollision(i).getGeometry().getName());
}
//Draw the ray to see what it looks like
if (rootNode.getChild("Debug Node") != null)
rootNode.detachChildNamed("Debug Node");
Node debugNode = new Node("Debug Node");
rootNode.attachChild(debugNode);
Geometry geoRay = new Geometry("GeoRay",
new Line(ray.origin, ray.origin.add(ray.direction.mult(ray.limit))));
Material matRay = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matRay.setColor("Color", ColorRGBA.Green);
geoRay.setMaterial(matRay);
debugNode.attachChild(geoRay);
}
}
}, "Check collision");
//Add crosshairs to the screen
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
int renderedSize = guiFont.getCharSet().getRenderedSize();
BitmapText crosshairs = new BitmapText(guiFont);
crosshairs.setName("crosshairs");
crosshairs.setText("+");
crosshairs.setSize(renderedSize * 1.5f);
crosshairs.setColor(ColorRGBA.White);
crosshairs.setLocalTranslation(
(cam.getWidth() / 2f) - (crosshairs.getLineWidth() / 2f),
(cam.getHeight() / 2f) + (crosshairs.getLineHeight() / 2f), 0);
guiNode.attachChild(crosshairs);
}
This doesn’t happen with boxes, even if they are very thin, so probably quads are treated in a different way.