False negative scene.pickWithRay pick.hit result

Hi. Use cannojs as phys engine. After upgrading to bjs 5.18.0 i register false negative results from scene.pickWithRay(). It gets some false results every ~1 second. It breaks movement logic.

const pick = this._scene.pickWithRay(this._playerGroundRay);
if (pick) {
this._onObject = pick.hit; // here pick.hit false negative sometimes

Resently i report a bug with physics heightmap impostor and in 5.18.0 this bug was fixed Fxi heightmap impostor with Cannon by CedricGuillemet · Pull Request #12818 · BabylonJS/Babylon.js · GitHub
ground heightmap impostor broken since BJS 5.5.6 · Issue #12578 · BabylonJS/Babylon.js · GitHub
But now i faced up with this.

My ground is created from heightmap with impostor:

ground.physicsImpostor = new PhysicsImpostor(
{ mass: 0 }

In bjs 5.17.0 it works perfect. No code was changed, only upgrading to 5.18.0.

Hi @emp , how are you doing? Welcome to the Babylon.js forum!

I will check with the other members of the team to see what is going on there.

Also, would you mind creating a playground example to help us test?

1 Like

Hi! Thanks for response!
This is a pg: Babylon.js Playground

Check console.log, you will see “false” at the start when playing. But i cant reproduce exactly worse behaviour like in my project (many infinity false positives). I will try to update pg to catch more but it will takes a time.

1 Like

Second strange thing in my pg is when a sphere rotates, the ray shows the pick.hit = true even when ray is not touched the ground.

I think I might have narrowed down the issue… but it won t be simple :slight_smile:

This boils down to a precision issue with the numerical values computing by the physics engine. Their steps are so small, it creates some issues in running the triangle-ray intersection algorithm.

I actually extracted some values for the current raycast function to double check it:

@RaananW will be back next week and might have a workaround for it ?

That’s a precision issue, you are totally right.

You can see it here - false negative pickWithRay physics | Babylon.js Playground (babylonjs.com)

Check the logs and you will see that the ground’s position is not 0,0,0 (but almost :-)) and the fixed rays I have created are returning false after a while.

This is physics-engine related. Something you can do is force a position on impostors that are fixed:

false negative pickWithRay physics | Babylon.js Playground (babylonjs.com)

Or make the rays a little longer:

false negative pickWithRay physics | Babylon.js Playground (babylonjs.com)


Hello @emp just checking in if there’s anything else you’d like help with?

1 Like

Hello! I marked solution, big thanks for all!

1 Like