reactphysics3d icon indicating copy to clipboard operation
reactphysics3d copied to clipboard

MeshCollider raycast bug

Open EvelynY opened this issue 2 years ago • 2 comments

// in TriangleShape::raycast const decimal sign = (localHitPoint - ray.point1).dot(pq) > FLT_MIN ? 1.0f : -1.0f; // hitFraction must multiply sign here, sometimes the point is not on the ray . const decimal hitFraction = sign * (localHitPoint - ray.point1).length() / pq.length();

if (hitFraction < decimal(0.0) || hitFraction > ray.maxFraction) return false;

EvelynY avatar Feb 10 '23 07:02 EvelynY

Can I please ask you to explain the issue with text? Where does this code coming from exactly? What do you expect and what is wrong?

DanielChappuis avatar Feb 10 '23 08:02 DanielChappuis

I am using reactphysics3d for camera collider in my project, by moving away the camera from the meshcollider that obstruct the view. But sometimes the raycast not work well, here is my test data. ray : { point1 = (x = -11.6768284, y = 7.62946081, z = -6.41031027) point2 = (x = -6.94290876, y = 7.38909339, z = -5.27299595) maxFraction = 1 }, mesh triangle : { [0] = (x = -11.5843544, y = 10.4978685, z = -7.63218307) [1] = (x = -12.3325634, y = 5.11047888, z = -6.35258769) [2] = (x = -12.3325634, y = 10.4978685, z = -6.35258769) }, the raycast result point is: { (x = -12.2221985, y = 7.65715217, z = -6.54133463) }, but the result is not on the ray, this cause my bug, it's on the positive of the ray, you can try my test data. That code is copy from TriangleShape.cpp in reactphysics3d source, I add ‘const decimal sign = (localHitPoint - ray.point1).dot(pq) > FLT_MIN ? 1.0f : -1.0f; ’ fixed the bug. Here is a video to explain my problem: https://user-images.githubusercontent.com/3447313/218084213-a08a5814-c16d-4433-9d71-0fedec87b493.MP4

EvelynY avatar Feb 10 '23 11:02 EvelynY