示例#1
0
    /// <summary>
    /// Attempts to perform a jump down from a one way platform
    /// </summary>
    /// <returns></returns>
    public bool AttemptDropDownJump()
    {
        if (CurrentMovementType != EMovementType.CROUCH)
        {
            return(false);
        }
        EHBounds2D ColliderBounds = AssociatedCollider.GetBounds();
        EHRect2D   CastBox        = new EHRect2D();

        CastBox.RectPosition = ColliderBounds.MinBounds + Vector2.down * .1f;
        CastBox.RectSize     = new Vector2(ColliderBounds.MaxBounds.x - ColliderBounds.MinBounds.x, .1f);
        bool bIsUnderOneWayPlatform = false;

        if (EHPhysicsManager2D.BoxCastAll2D(ref CastBox, EHBaseCollider2D.EColliderType.STATIC, out EHBaseCollider2D[] ColliderWeHitList, LayerMask.GetMask(ENVIRONMENT_LAYER)))
        {
            foreach (EHBaseCollider2D ColliderWeHit in ColliderWeHitList)
            {
                if (!(ColliderWeHit is EHOneSidedBoxCollider2D))
                {
                    return(false);
                }
                else
                {
                    bIsUnderOneWayPlatform = true;
                }
            }
        }
        return(bIsUnderOneWayPlatform);
    }
示例#2
0
    public EHBounds2D GetBounds()
    {
        EHBounds2D Bounds = default;

        Bounds.MinBounds = MinBounds;
        Bounds.MaxBounds = MaxBounds;
        return(Bounds);
    }
示例#3
0
    public override bool PushOutCollider(EHBaseCollider2D ColliderToPushOut)
    {
        EHBox2DCollider OtherRectCollier = (EHBox2DCollider)ColliderToPushOut;

        if (OtherRectCollier == null)
        {
            return(false);
        }

        if (RectGeometry.IsOverlappingRect(OtherRectCollier.PhysicsSweepGeometry))
        {
            FHitData HitData = new FHitData();
            HitData.OwningCollider = this;
            HitData.OtherCollider  = ColliderToPushOut;

            EHBounds2D ThisCurrentBounds   = RectGeometry.GetBounds();
            EHBounds2D OtherCurrentBounds  = OtherRectCollier.RectGeometry.GetBounds();
            EHBounds2D ThisPreviousBounds  = PreviousRectGeometry.GetBounds();
            EHBounds2D OtherPreviousBounds = OtherRectCollier.PreviousRectGeometry.GetBounds();

            Vector2 RightUpOffset    = ThisCurrentBounds.MaxBounds - OtherCurrentBounds.MinBounds;
            Vector2 LeftBottomOffset = ThisCurrentBounds.MinBounds - OtherCurrentBounds.MaxBounds;



            if (ThisPreviousBounds.MaxBounds.y < OtherPreviousBounds.MinBounds.y && RightUpOffset.y > 0 && (CollisionMask & (byte)ECollisionDirection.UP) != 0)
            {
                ColliderToPushOut.transform.position += Vector3.up * RightUpOffset.y;
                HitData.HitDirection = Vector2.down;
            }
            else if (ThisPreviousBounds.MaxBounds.x < OtherPreviousBounds.MinBounds.x && RightUpOffset.x > 0 && (CollisionMask & (byte)ECollisionDirection.RIGHT) != 0)
            {
                ColliderToPushOut.transform.position += Vector3.right * RightUpOffset.x;
                HitData.HitDirection = Vector2.left;
            }
            else if (ThisPreviousBounds.MinBounds.x > OtherPreviousBounds.MaxBounds.x && LeftBottomOffset.x < 0 && (CollisionMask & (byte)ECollisionDirection.LEFT) != 0)
            {
                ColliderToPushOut.transform.position += Vector3.right * LeftBottomOffset.x;
                HitData.HitDirection = Vector2.right;
            }
            else if (ThisPreviousBounds.MinBounds.y > OtherPreviousBounds.MaxBounds.y && LeftBottomOffset.y < 0 && (CollisionMask & (byte)ECollisionDirection.DOWN) != 0)
            {
                ColliderToPushOut.transform.position += Vector3.up * LeftBottomOffset.y;
                HitData.HitDirection = Vector2.up;
            }

            if (!ContainOverlappingCollider(ColliderToPushOut) || MatchesOverlappingHitData(ColliderToPushOut, ref HitData))
            {
                AddColliderToHitSet(ColliderToPushOut, HitData);
            }

            HitCollisionStay(ColliderToPushOut, HitData);

            return(true);
        }
        return(false);
    }
示例#4
0
    public static void DebugDrawRect(EHRect2D Rect, Color DebugColor, bool Fill = false)
    {
#if UNITY_EDITOR
        EHBounds2D Bounds    = Rect.GetBounds();
        Rect       UnityRect = new Rect(Bounds.MinBounds, Rect.RectSize);
        Color      FillColor = DebugColor;

        if (Fill)
        {
            FillColor.a *= .25f;
        }
        else
        {
            FillColor.a = 0;
        }
        UnityEditor.Handles.DrawSolidRectangleWithOutline(UnityRect, FillColor, DebugColor);
#endif
    }
示例#5
0
        public override void OnStateTick(float DeltaTime)
        {
            float Distance = Vector2.Distance(TargetTransform.position, AIControllerOwner.transform.position);

            if (Distance < Range)
            {
                EHBounds2D PlayerCharacterBounds  = PlayerCollider.GetBounds();
                Vector3    CenterColliderPosition = PlayerCharacterBounds.MinBounds + (PlayerCharacterBounds.MaxBounds - PlayerCharacterBounds.MinBounds) / 2f;
                Vector2    DirectionToFly         = CenterColliderPosition - AIControllerOwner.transform.position;
                DirectionToFly.Normalize();
                WispController.FlightMovement.SetHorizontalInput(DirectionToFly.x);
                WispController.FlightMovement.SetVerticalInput(DirectionToFly.y);
            }
            else
            {
                WispController.FlightMovement.SetVerticalInput(0);
                WispController.FlightMovement.SetHorizontalInput(0);
            }
        }
示例#6
0
    public override void UpdateColliderBounds(bool bUpdatePreviousBounds)
    {
        if (bUpdatePreviousBounds)
        {
            PreviousRectGeometry = RectGeometry;
            if (ColliderType == EColliderType.PHYSICS)
            {
                PreviousRectGeometry.RectPosition += BUFFER;
                PreviousRectGeometry.RectSize     -= (2 * BUFFER);
            }
        }

        Vector2 RectSize      = ColliderSize * transform.localScale;
        Vector2 WorldPosition = transform.position;
        Vector2 RectPosition;

        if (bIsCharacterCollider)
        {
            RectPosition = ColliderOffset + WorldPosition - (Vector2.right * RectSize.x / 2);
        }
        else
        {
            RectPosition = ColliderOffset + WorldPosition - (RectSize / 2);
        }
        RectGeometry.RectSize     = RectSize;
        RectGeometry.RectPosition = RectPosition;

        if (ColliderType == EColliderType.PHYSICS)//Create a sweep bounds so that we do not phase through collisions when going at top speeds
        {
            EHBounds2D RectBounds     = RectGeometry.GetBounds();
            EHBounds2D PreviousBounds = PreviousRectGeometry.GetBounds();

            Vector2 MinBounds = new Vector2(Mathf.Min(RectBounds.MinBounds.x, PreviousBounds.MinBounds.x), Mathf.Min(RectBounds.MinBounds.y, PreviousBounds.MinBounds.y));
            Vector2 MaxBounds = new Vector2(Mathf.Max(RectBounds.MaxBounds.x, PreviousBounds.MaxBounds.x), Mathf.Max(RectBounds.MaxBounds.y, PreviousBounds.MaxBounds.y));

            PhysicsSweepGeometry.RectPosition = MinBounds;
            PhysicsSweepGeometry.RectSize     = MaxBounds - MinBounds;
        }
    }