Problem with getting the closest hit from a ray

Hi again!

Today I wanted to implement my steering behaviour and to see whats in front of my characters I cast a ray in the direction they are heading to see if anything is in their way.

I want to slow the character down if it comes close to an obstacle, and therefore I wanted to get the closest intersection with the ray via

Ray ray = new Ray(psd, direction);
         PickResults results = new BoundingPickResults();

PickData closest = results.getPickData(0);

The first problem is that the results are not sorted by their distance as stated in the manual and I saw that calling results.getPickData alters the content of results.
Therefore I cant even loop through all the results and find the closest distance by hand since calling results.getPickData changes which result is at which index within the results.

Any thoughts?
Im not using any multithreading that could alter the results why I search through them.
And I also displayed a Line to represent my ray to see if the ray to see if I cast the ray correctly and the line looks just fine.

Ok I figured some things out.

The getPickData method modifies the entries because they only get sorted if getPickData is called.

The other problem I had was caused by casting the ray from within the character and thus getPickData(0) allways returned 0.

But now I have a different problem. The Ray sometimes finds intersections where I cant see any.

I know that probably nobody can help my with that, so I guess I just have to keep trying.

ok to fix your first problem, you can use two nodes.

the first node, player node, holds your player. the other node, whatever you want to call it, holds the rest of the scene data. lets call this other node "SceneNode". make sure they are both attached to the rootNode.

then, pick SceneNode and the 'player' should NOT be picked.

Also, the reason you are getting pick interesections where you cant see anything is because you are using a bounding pick, rather than a triangle pick. BoundingPickResults gets the intersection of your ray and the bounding volume of whatever you are picking.

try using TrianglePickResults instead of BoundingPickResults.