PhysicsSpace rayTest result sorting

Hi, I started a new project recently with jME and I’m playing around with the physics system.

I’m using rayTest() for picking, the problem I have is that the results are sorted in the order the objects were added to the space and not by proximity (like when using Ray collisions).
I want to know which is the nearest so I don’t shot enemies behind walls.
How would you suggest I’d do that?
Doing a Ray collision with the results from the rayTest()? doing a Ray collision from the beginning? Sorting the results manually?


The “hitFraction” parameter of the PhysicsRayTestResult tells you at what distance (in terms of length of the original picking vector) the collision occurred.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

1 Like

Oh! That’s great.

Thank you!


1 Like