Ray Collision bug (with test case)

I’ve had a problem with CollisionResults returning empty, when it is clearly intersecting with an object. I made a simple test case that prints out the number of collisions found when you left click the mouse. If you click anywhere in the blue region, it should output “1”. However, 10-20% of the time, it outputs “0”.

[snippet id=“78”]

Edit: This problem still occurs if I replace the custom Landscape mesh, and replace it with

[snippet id=“79”]

But it works fine if I use

[snippet id=“80”]

So here is a 2nd, smaller test case using a box instead of the custom mesh. When you left click on the blue area, it should output “2”, but sometimes it outputs 0.

[snippet id=“81”]

Edit2: This problem seems to be related to this: http://hub.jmonkeyengine.org/groups/terramonkey/forum/topic/collision-ray-seems-to-miss-terrainquad/


It seems that using a boundingBox with 0 volume causes the collideWith method to have some problems. If you add

[snippet id=“82”]

to the second test case, it works fine then.

Its a known issue: http://code.google.com/p/jmonkeyengine/issues/detail?id=455

A fix is always welcome :slight_smile:

1 Like

Thanks, I might look into a solution later, but I’m not familiar enough with jME3 yet.

Here is my current workaround, if anyone is interested.

Since this bug only occurs in my custom mesh, if the bounding box extend is 0, I simply change it to something small like 0.01, as shown below. You might have to check the other extents too if those can possibly be 0.

[snippet id=“83”]