You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pb_HandleUtility.ObjectRaycast returns normally the closest object hit by the ray. However, when using MeshRaycast, it transfers the ray to local coordinates, and then return the "local computed distance". When using scaling, this can end up to wrong object selection. The distance must be scaled back to a common base (global coordinates, or percentage) before being compared to other distance.
Here the code to scale back to global
public static bool MeshRaycast(Mesh mesh, Ray ray, out pb_RaycastHit hit, Transform transform)
{
...
if(pb_Geometry.RayIntersectsTriangle(ray, a, b, c, Culling.Front, out dist, out point))
{
hit = new pb_RaycastHit();
hit.point = point;
hit.distance = Vector3.Distance(transform.TransformPoint(hit.point), transform.TransformPoint(ray.origin));
hit.normal = Vector3.Cross(b-a, c-a);
hit.triangle = new int[] { triangles[i], triangles[i+1], triangles[i+2] };
return true;
...
}
I think you could return distance as a percentage too, so you wouldn't need to pass the transform to the function. However it means that your ray have a certain defined length, which is usually not the case.
The text was updated successfully, but these errors were encountered:
pb_HandleUtility.ObjectRaycast returns normally the closest object hit by the ray. However, when using MeshRaycast, it transfers the ray to local coordinates, and then return the "local computed distance". When using scaling, this can end up to wrong object selection. The distance must be scaled back to a common base (global coordinates, or percentage) before being compared to other distance.
Here the code to scale back to global
I think you could return distance as a percentage too, so you wouldn't need to pass the transform to the function. However it means that your ray have a certain defined length, which is usually not the case.
The text was updated successfully, but these errors were encountered: