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

            direction.Normalize();

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

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

            FP angle = TSVector2.Angle(direction, TSVector2.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;
            }

            TSVector2 center = origin + offsetToCenter;

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

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

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

                return(resultHit);
            }
        }
        public TSRaycastHit2D Raycast(TSVector2 origin, TSVector2 direction, FP distance)
        {
            TSRaycastHit2D result = null;

            Func <TrueSync.Physics2D.Fixture, TSVector2, TSVector2, FP, FP> callback = delegate(TrueSync.Physics2D.Fixture fixture, TSVector2 point, TSVector2 normal, FP fraction) {
                result = new TSRaycastHit2D(gameObjectMap[fixture.Body].GetComponent <TSCollider2D>());
                return(0);
            };

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

            return(result);
        }