public TSRaycastHit Raycast(TSRay ray, FP maxDistance, RaycastCallback callback = null)
        {
            IBody    hitBody;
            TSVector hitNormal;
            FP       hitFraction;

            TSVector origin    = ray.origin;
            TSVector direction = ray.direction;

            if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction))
            {
                if (hitFraction <= maxDistance)
                {
                    GameObject  other              = PhysicsManager.instance.GetGameObject(hitBody);
                    TSRigidBody bodyComponent      = other.GetComponent <TSRigidBody>();
                    TSCollider  colliderComponent  = other.GetComponent <TSCollider>();
                    TSTransform transformComponent = other.GetComponent <TSTransform>();
                    return(new TSRaycastHit(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);
                    TSRigidBody bodyComponent      = other.GetComponent <TSRigidBody>();
                    TSCollider  colliderComponent  = other.GetComponent <TSCollider>();
                    TSTransform transformComponent = other.GetComponent <TSTransform>();
                    return(new TSRaycastHit(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, direction, hitFraction));
                }
            }
            return(null);
        }
示例#2
0
        public static bool Raycast(TSVector rayOrigin, TSVector rayDirection, out TSRaycastHit hit, FP maxDistance, int layerMask = UnityEngine.Physics.DefaultRaycastLayers)
        {
            TSRay ray = new TSRay(rayOrigin, direction: rayDirection);

            hit = PhysicsWorldManager.instance.Raycast(ray, maxDistance, layerMask: layerMask);
            if (hit != null)
            {
                if (hit.distance <= maxDistance)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#3
0
        public TSRaycastHit Raycast(TSRay ray, FP maxDistance, int layerMask, RaycastCallback callback = null)
        {
            IBody    hitBody;
            TSVector hitNormal;
            FP       hitFraction;

            TSVector origin    = ray.origin;
            TSVector direction = ray.direction;

            direction *= maxDistance;
            if (Raycast(origin, direction, callback, layerMask, out hitBody, out hitNormal, out hitFraction))
            {
                GameObject  other = PhysicsManager.instance.GetGameObject(hitBody);
                TSTransform transformComponent = transformMap[hitBody];
                TSRigidBody bodyComponent      = transformComponent.rb;
                TSCollider  colliderComponent  = transformComponent.tsCollider;
                hit.Init(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, ray.direction, hitFraction);
                return(hit);
            }

            return(null);
        }
示例#4
0
 public TSRaycastHit Raycast(TSRay ray, FP maxDistance, RaycastCallback callback = null)
 {
     throw new NotImplementedException();
 }