Wall Jump doesn't Working

My Wall Jump Was Working Normally But I Were trying to add collider detector for my enemy then that happens:

this is my Wall Jump Script :point_down:

public float WallSlidForce;
public float WallJumpDuration = 0.3f;
private float WallSlideDirection;
private float WallJumpTimer = 0.2f;
private float WallJumpTime;
public bool IsWallSliding;
private bool IsWallJumping;

void Update()
{

    if ( CanMove)
    {
        if (!IsCroushing )
            rb.velocity = new Vector2(HorizontalMovement * WalkForce, rb.velocity.y);
        else if (IsCroushing)
            rb.velocity = new Vector2(HorizontalMovement * CroushForce, rb.velocity.y);
        Flip();
    }
    
    WallSliding();
    WallJump();
    MoveChecking();
}
 public void Jump(InputAction.CallbackContext context)
 {
     if (context.performed && !IsDashing && !IsCroushing)
     {
         if (!IsWallSliding && JumpLeft > 0 && !Ck.IsGrounded)
         {
             rb.velocity = new Vector2(rb.velocity.x, JumpForce);
             JumpLeft--;
             Jump2 = true;
         }
         if (Ck.IsGrounded)
         {
             rb.velocity = new Vector2(rb.velocity.x, JumpForce);
         }

     }
     else if (context.canceled)
         rb.velocity = new Vector2(rb.velocity.x,rb.velocity.y * 0.5f);
     if (context.performed && WallJumpTime > 0f && !IsCroushing)
     {
         if (HorizontalMovement != 0)
         {
             IsWallJumping = true;
             rb.velocity = new Vector2(WallSlideDirection * WallJumpForce.x, WallJumpForce.y);
             WallJumpTime = 0f;
         }
         else
         {
             IsWallJumping= true;
             rb.velocity = new Vector2 (WallSlideDirection * WallJumpForce.x , rb.velocity.y);
             WallJumpTime = 0f;
         }
         
         if (transform.localScale.x != WallSlideDirection)
         {
             IsFacingRight = !IsFacingRight;
             Vector2 ls = transform.localScale;
             ls.x *= -1f;
             transform.localScale = ls;
         }
         Invoke(nameof(StopWallJump),WallJumpDuration);
     }
     if (context.performed && IsCroushing && !Ck.IsTouchingFloor)
     {
         rb.velocity = new Vector2(rb.velocity.x, JumpForce);
         StopCroushing();
     }

 }
 private void WallSliding()
 {
     if (Ck.IsTouchingWall && !Ck.IsGrounded && !IsDashing)
     {
             rb.velocity = new Vector2(rb.velocity.x, -WallSlidForce);
             IsWallSliding = true;
     }
     else IsWallSliding = false;
 }

 private void WallJump()
 {
     if (IsWallSliding)
     {
         IsWallJumping = false;
         WallSlideDirection = -transform.localScale.x;
         WallJumpTime = WallJumpTimer;
         CancelInvoke(nameof(StopWallJump));
     }
     else WallJumpTime -= Time.deltaTime;
 }
private void StopWallJump()
{
    IsWallJumping = false;
}
    private void MoveChecking()
    {
        if (!IsWallSliding && !IsDashing && !IsSliding && !IsWallJumping && !IsAttacking)
            CanMove = true;
        else CanMove = false;
    }

image

1 Answer

1

Reset IsWallSliding Flag after performing a wall jump.

Add a line after performing wall jump to reset IsWallSliding flag back to false. This should prevent your player from trying to wall slide while jumping and will allow the player to jump away from the wall after they jump.

:man_shrugging:t5: Now I could be wrong but I hope this helps. If it doesn’t let me know.

Thanks bro you Saved me

I’m just glad you understood my poor grammar :joy: