コード例 #1
0
        public static object _CircleCast(FPVector2 origin, FP radius, FPVector2 direction, FP distance, Physics2D.BodySpecialSensor sensorType, int layerMask = UnityEngine.Physics.DefaultRaycastLayers)
        {
            if (distance + radius > FP.MaxValue)
            {
                distance = FP.MaxValue - radius;
            }

            direction.Normalize();

            FPVector2 offsetToCenter = ((direction * distance) * FP.Half);

            offsetToCenter.x = FP.Abs(offsetToCenter.x);
            offsetToCenter.y = FP.Abs(offsetToCenter.y);

            FP angle = FPVector2.Angle(direction, FPVector2.right);

            if (direction.x <= 0 && direction.y >= 0)
            {
                offsetToCenter.x = -offsetToCenter.x;
            }
            else if (direction.x <= 0 && direction.y <= 0)
            {
                offsetToCenter.x = -offsetToCenter.x;
                offsetToCenter.y = -offsetToCenter.y;
                angle            = -angle;
            }
            else if (direction.x >= 0 && direction.y <= 0)
            {
                offsetToCenter.y = -offsetToCenter.y;
                angle            = -angle;
            }

            FPVector2 center = origin + offsetToCenter;

            object result = _OverlapCapsule(center, new FPVector2(distance + radius * 2, radius * 2), FPCapsuleDirection2D.HORIZONTAL, -angle, sensorType, layerMask);

            if (result is FPCollider2D)
            {
                return(new FPRaycastHit2D((FPCollider2D)result));
            }
            else
            {
                FPCollider2D[]   resultAux = (FPCollider2D[])result;
                FPRaycastHit2D[] resultHit = new FPRaycastHit2D[resultAux.Length];

                for (int index = 0; index < resultHit.Length; index++)
                {
                    resultHit[index] = new FPRaycastHit2D(resultAux[index]);
                }

                return(resultHit);
            }
        }
コード例 #2
0
        public FPRaycastHit2D Raycast(FPVector2 origin, FPVector2 direction, FP distance)
        {
            FPRaycastHit2D result = null;

            Func <Spax.Physics2D.Fixture, FPVector2, FPVector2, FP, FP> callback = delegate(Spax.Physics2D.Fixture fixture, FPVector2 point, FPVector2 normal, FP fraction)
            {
                result = new FPRaycastHit2D(gameObjectMap[fixture.Body].GetComponent <FPCollider2D>());
                return(0);
            };

            world.RayCast(callback, origin, origin + direction * distance);

            return(result);
        }