public FPRaycastHit Raycast(FPRay ray, FP maxDistance, RaycastCallback callback = null) { IBody hitBody; FPVector hitNormal; FP hitFraction; FPVector origin = ray.origin; FPVector direction = ray.direction; if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction)) { if (hitFraction <= maxDistance) { GameObject other = PhysicsManager.instance.GetGameObject(hitBody); FPRigidBody bodyComponent = other.GetComponent <FPRigidBody>(); FPCollider colliderComponent = other.GetComponent <FPCollider>(); FPTransform transformComponent = other.GetComponent <FPTransform>(); return(new FPRaycastHit(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, ray.direction, hitFraction)); } } else { direction *= maxDistance; if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction)) { GameObject other = PhysicsManager.instance.GetGameObject(hitBody); FPRigidBody bodyComponent = other.GetComponent <FPRigidBody>(); FPCollider colliderComponent = other.GetComponent <FPCollider>(); FPTransform transformComponent = other.GetComponent <FPTransform>(); return(new FPRaycastHit(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, direction, hitFraction)); } } return(null); }
public static bool Raycast(FPVector rayOrigin, FPVector rayDirection, out FPRaycastHit hit, FP maxDistance, int layerMask = UnityEngine.Physics.DefaultRaycastLayers) { FPRay ray = new FPRay(rayOrigin, direction: rayDirection); hit = PhysicsWorldManager.instance.Raycast(ray, maxDistance, layerMask: layerMask); if (hit != null) { if (hit.distance <= maxDistance) { return(true); } } return(false); }