예제 #1
0
    public static bool RayTrace2D(ref EHRayTraceParams Params, out EHRayTraceHit RayHit, int LayerMask = 0, bool bDebugDraw = false)
    {
        if (CachedInstance == null)
        {
            Debug.LogWarning("Game Overseer has not been initialized");
            RayHit = default;
            return(false);
        }
        RayHit = default;
        EHRayTraceHit TempRayTraceHit;
        float         ClosestDistance = -1;
        bool          bMadeCollision  = false;

        foreach (KeyValuePair <EHBaseCollider2D.EColliderType, HashSet <EHBaseCollider2D> > ColliderSet in CachedInstance.ColliderComponentDictionary)
        {
            if (RayTrace2D(ref Params, ColliderSet.Key, out TempRayTraceHit, LayerMask, bDebugDraw))
            {
                float CollisionDistance = Vector2.Distance(Params.RayOrigin, TempRayTraceHit.HitPoint);
                if (!bMadeCollision || ClosestDistance > CollisionDistance)
                {
                    ClosestDistance = CollisionDistance;
                    RayHit          = TempRayTraceHit;
                    bMadeCollision  = true;
                }
            }
        }
        return(bMadeCollision);
    }
예제 #2
0
    protected bool CastRayFromVelocity(Vector2 OriginPosition, out EHRayTraceHit RayHit, int LayerMask = 0, bool bDebugDrawLines = false)
    {
        Vector2          ProjectileVelocity = Physics2D.Velocity;
        EHRayTraceParams Params             = new EHRayTraceParams();

        Params.RayOrigin    = OriginPosition;
        Params.RayDirection = ProjectileVelocity.normalized;
        Params.RayLength    = ProjectileVelocity.magnitude * EHTime.DeltaTime;
        return(EHPhysicsManager2D.RayTrace2D(ref Params, out RayHit, LayerMask, bDebugDrawLines));
    }
예제 #3
0
 public override bool IsRayTraceOverlapping(ref EHRayTraceParams Ray, out EHRayTraceHit RayHit)
 {
     if (RectGeometry.DoesLineIntersect(Ray.RayOrigin, Ray.RayOrigin + Ray.RayDirection * Ray.RayLength, out Vector2 IntersectPoint))
     {
         RayHit             = new EHRayTraceHit();
         RayHit.HitPoint    = IntersectPoint;
         RayHit.HitCollider = this;
         return(true);
     }
     RayHit = default;
     return(false);
 }
    public override bool IsRayTraceOverlapping(ref EHRayTraceParams Ray, out EHRayTraceHit RayHit)
    {
        if (!base.IsRayTraceOverlapping(ref Ray, out RayHit))
        {
            return(false);
        }
        Vector2 OriginPoint = Ray.RayOrigin;

        switch (CollisionDirection)
        {
        case ECollisionDirection.UP:
            if (OriginPoint.y < RectGeometry.GetBounds().MaxBounds.y)
            {
                return(false);
            }
            break;

        case ECollisionDirection.DOWN:
            if (OriginPoint.y > RectGeometry.GetBounds().MinBounds.y)
            {
                return(false);
            }
            break;

        case ECollisionDirection.RIGHT:
            if (OriginPoint.x < RectGeometry.GetBounds().MaxBounds.x)
            {
                return(false);
            }
            break;

        case ECollisionDirection.LEFT:
            if (OriginPoint.x > RectGeometry.GetBounds().MinBounds.y)
            {
                return(false);
            }
            break;
        }

        return(true);
    }
예제 #5
0
    public static bool RayTrace2D(ref EHRayTraceParams Params, EHBaseCollider2D.EColliderType ColliderType, out EHRayTraceHit RayHit, int LayerMask = 0, bool DebugDraw = false)
    {
        if (!CachedInstance.ColliderComponentDictionary.ContainsKey(ColliderType))
        {
            RayHit = default;
            return(false);
        }

        bool  bCollisionMade  = false;
        float ClosestDistance = -1;

        RayHit = default;
        EHRayTraceHit TempRayHit;

        foreach (EHBaseCollider2D Collider in CachedInstance.ColliderComponentDictionary[ColliderType])
        {
            if (Collider.IsRayTraceOverlapping(ref Params, out TempRayHit))
            {
                float CollisionDistance = Vector2.Distance(Params.RayOrigin, TempRayHit.HitPoint);
                if (!bCollisionMade || ClosestDistance > CollisionDistance)
                {
                    ClosestDistance = CollisionDistance;
                    RayHit          = TempRayHit;
                    bCollisionMade  = true;
                }
            }
        }

#if UNITY_EDITOR
        if (DebugDraw)
        {
            EHDebug.RayTraceDrawLine(Params, bCollisionMade ? Color.red : Color.yellow);
        }
#endif

        return(bCollisionMade);
    }
예제 #6
0
 /// <summary>
 /// Draws a debug line
 /// </summary>
 /// <param name="RayParams"></param>
 public static void RayTraceDrawLine(EHRayTraceParams RayParams, Color LineColor)
 {
     Debug.DrawLine(RayParams.RayOrigin, RayParams.RayOrigin + RayParams.RayDirection * RayParams.RayLength, LineColor);
 }
예제 #7
0
 public static void RayTraceDrawLine(EHRayTraceParams RayParams)
 {
     RayTraceDrawLine(RayParams, Color.red);
 }
예제 #8
0
 /// <summary>
 /// Checks to see if the ray that is passed in is overlapping the collider
 /// </summary>
 /// <param name="Ray"></param>
 /// <returns></returns>
 public abstract bool IsRayTraceOverlapping(ref EHRayTraceParams Ray, out EHRayTraceHit RayHit);