示例#1
0
        //Todo: No need to apply rotation to ray for sphere.
        public static bool Raycast(Ray ray, SphereCollider sphere, RigidTransform sphereTransform, out RaycastResult result)
        {
            var  rayInSphereSpace = Ray.TransformRay(math.inverse(sphereTransform), ray);
            bool hit = Raycasting.RaycastSphere(rayInSphereSpace, sphere, out float fraction, out float3 normal);

            result.position = math.lerp(ray.start, ray.end, fraction);
            result.normal   = math.rotate(sphereTransform, normal);
            result.distance = math.distance(ray.start, result.position);
            return(hit);
        }
示例#2
0
        public static bool Raycast(Ray ray, BoxCollider box, RigidTransform boxTransform, out RaycastResult result)
        {
            var  rayInBoxSpace = Ray.TransformRay(math.inverse(boxTransform), ray);
            bool hit           = Raycasting.RaycastBox(rayInBoxSpace, box, out float fraction, out float3 normal);

            result.position = math.lerp(ray.start, ray.end, fraction);
            result.normal   = math.rotate(boxTransform, normal);
            result.distance = math.distance(ray.start, result.position);
            return(hit);
        }