cannon-es icon indicating copy to clipboard operation
cannon-es copied to clipboard

BUG: RaycastAll fails to detect sleeping and static bodies at expected y position

Open johnnyrainbow opened this issue 1 year ago • 2 comments

I have found a bug where all Raycasts fail to detect intersections against the correct y position of sleeping or static bodies when the world has gravity, and their y positions are not grounded. (for example a floating static cube at y=5 in a world with -9.8 gravity will never be raycasted unless you cast only on the y axis.)

I made a code sandbox demonstrating the issue. https://codesandbox.io/p/sandbox/cannon-raycast-forked-x6yft5 (You can see in the console that it shows raycast results for only the non sleeping stacked cubes.)

johnnyrainbow avatar Jan 09 '24 02:01 johnnyrainbow

Note for anyone following this or who has the same issue - I added my own temporary fix. The issue stems from the body aabb not updating due to it being either static or sleeping obviously (aabbNeedsUpdate is false), so the aabb is wrong when the raycaster interacts. I fixed it by adding another aabb (ghostabb) to Body class that does update for the sleeping/static body.

This way we can do the raycast against Body.ghostabb, and leave the real aabb as normal

johnnyrainbow avatar Jan 09 '24 17:01 johnnyrainbow

Note for anyone following this or who has the same issue - I added my own temporary fix. The issue stems from the body aabb not updating due to it being either static or sleeping obviously (aabbNeedsUpdate is false), so the aabb is wrong when the raycaster interacts. I fixed it by adding another aabb (ghostabb) to Body class that does update for the sleeping/static body.

This way we can do the raycast against Body.ghostabb, and leave the real aabb as normal

Can u share your code? I don't understand

CrazyWords1 avatar Apr 04 '24 11:04 CrazyWords1