Exemplo n.º 1
0
    /// <summary>
    /// Call this to actually perform a wall jump
    /// </summary>
    public void PerformWallJump()
    {
        if (ColliderWeAreOn)
        {
            CharacterMovement.ResetCachedGravityScaled();
            Vector2 AdjustedLaunchVelocity = new Vector2(WallJumpVelocity.x * (CharacterMovement.GetIsFacingLeft() ? 1f : -1f), WallJumpVelocity.y);
            Physics2D.Velocity = AdjustedLaunchVelocity;

            CharacterMovement.SetIsFacingLeft(!CharacterMovement.GetIsFacingLeft(), true);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Coroutine that performs our character's dash based on the direction of their input and the dash
    /// animation curve
    /// </summary>
    /// <returns></returns>
    private IEnumerator PerformDash()
    {
        Vector2 MovementInputAxis = MovementComponent.GetMovementInput();

        Vector2 DashDirection;

        if (MovementInputAxis.x == 0)
        {
            MovementInputAxis = Vector2.right * (MovementComponent.GetIsFacingLeft() ? -1 : 1);
        }

        float HorizontalDashDirection = MovementInputAxis.x != 0 ? Mathf.Sign(MovementInputAxis.x) : 0;
        float VerticalDashDirection   = 0;//Mathf.Abs(MovementInputAxis.y) > EHCharacterMovementComponent.JOYSTICK_WALK_THRESHOLD ? Mathf.Sign(MovementInputAxis.y) : 0;

        DashDirection = new Vector2(HorizontalDashDirection, VerticalDashDirection);
        DashDirection.Normalize();

        MovementComponent.SetIsFacingLeft(DashDirection.x, true);
        float TimeThatHasPassed = 0;
        float CachedGravity     = Physics2D.GravityScale;

        Physics2D.GravityScale = 0;
        while (TimeThatHasPassed < DashTime && bIsPerformingDash)
        {
            Physics2D.Velocity = DashAnimationCurve.Evaluate(TimeThatHasPassed / DashTime) * DashDirection * DashSpeed;
            yield return(null);

            TimeThatHasPassed += EHTime.DeltaTime;
        }
        Physics2D.GravityScale = CachedGravity;
    }