Raycast inconsistent when using CannonJSPlugin?

When using CannonJSPlugin, raycasts are wavering between true and false when determining intersections.

Playground without CannonJSPlugin (consistently detects if player standing on object): https://www.babylonjs-playground.com/#3EDS3A#34

Playground with CannonJSPlugin (inconsistently detects if player standing on object): https://www.babylonjs-playground.com/#3EDS3A#35

The raycast is implemented the same in both Playgrounds. It’s a RayHelper starting from the bottom of the player (blue box) with length 0.1.

Note: For some reason, in both Playgrounds, the raycast has no problem determining whether the player (blue box) is standing on the white ground.

Could someone please shed light on why the raycast in the CannonJSPlugin Playground is wavering between true and false when determining intersections? Thank you :smiley:

It’s a good question why it happens, and I assume this is due to the constant position updates of the mesh and the fact that the position is not a flat integer.
You set the starting point to the exact edge of the mesh. The physics engine might “force” the upper mesh to get into the lower mesh (probably 0.000001 on the Y axis), but this is an uneducated guess. What I did find is that when you play with the values a little safer, it works correctly:

https://www.babylonjs-playground.com/#3EDS3A#36

2 Likes

Thank you so much for your time and help, @RaananW :smiley:

1 Like