Player not jumping horizontally when walljumping

This is the code I have written, don’t criticize the formatting or how “redundant” or “unreadable”
my code is as I simply do not care because it works for me.

{
// Components
private Rigidbody2D rb;
private Animator animator;
private SpriteRenderer spriteRenderer;

// Movement Settings
public float moveSpeed = 5f;
public float jumpForce = 10f;
private float horizontal;
public bool isFacingRight = true;

// Squish Settings
public float squishAmount = 100f; // Amount of squish on impact
public float squishDuration = 0.2f; // Duration of squish effect

// Strech Settings
public float stretchFactor = 120f; // How much to stretch vertically when falling
public float squishFactor = 80f; // How much to squish horizontally when falling
public float stretchSpeed = 10f; // Speed at which the stretch and squish effect is applied




// Dash Settings
public float dashForce = 20f; // Force applied during the dash
public float dashDuration = 0.2f; // How long the dash lasts
public float dashCooldown = 1f; // Cooldown before another dash can be performed
private bool isDashing = false;
private bool canDash = true;
private bool hasAirDashed = false; // Indicates if the player has dashed once in the air

float moveX;

// Impact Gravity Settings
public float impactGravity = 3f; // Increased gravity for impact effect
public float impactDuration = 2f; // Duration of increased gravity effect

// State Management
private bool isGrounded;
private bool wasGroundedLastFrame;

// Ground Check Settings
public Transform groundCheck;
public float groundCheckRadius = 20f;
public LayerMask groundLayer;

[SerializeField] private TrailRenderer tr;

public Transform wallCheck;
bool isWallTouch;
bool isSliding;
public float wallSlidingSpeed;
public float wallJumpDuration;
public Vector2 wallJumpForce;
bool isWallJumping;

private float previousYVelocity;
private float originalGravity;

void Start()
{
    // Initialize components
    rb = GetComponent<Rigidbody2D>();
    animator = GetComponent<Animator>(); // Assumes an Animator component is attached for animations
    spriteRenderer = GetComponent<SpriteRenderer>();
    originalGravity = rb.gravityScale;
}

void Update()
{
    // Check if grounded
    isGrounded = Physics2D.OverlapBox(groundCheck.position, new Vector2(0.8f, 0.2f), 0, groundLayer);

    if (isGrounded && !wasGroundedLastFrame)
    {
        canDash = true;
        hasAirDashed = false;
    }

    isWallTouch = Physics2D.OverlapBox(wallCheck.position, new Vector2(1.1f, 0.9f), -0.46f, groundLayer);

    if (isWallTouch && !isGrounded && moveX != 0)
    {
        isSliding = true;
    }
    else
    {
        isSliding = false;
    }
   
    if (isGrounded)
    {
        animator.SetBool("isJumping", false);
    }
    if (!isGrounded)
    {
        animator.SetBool("isJumping", true);
    }

    if (isWallTouch)
    {
        animator.SetBool("isWallTouch", true);
    }
    if (!isWallTouch)
    {
        animator.SetBool("isWallTouch", false);
    }

    if (isDashing)
    {
        tr.emitting = true;
    }

    if (!isDashing)
    {
        tr.emitting = false;
    }

    if (isWallJumping)
    {
        rb.velocity = new Vector2(-moveX * wallJumpForce.x, wallJumpForce.y);
    }
    else
    {
        rb.velocity = new Vector2(moveX * moveSpeed, rb.velocity.y);
    }

    // Handle movement and jumping
    HandleMovement();
    HandleJump();
    HandleDash();

    HandleStretchEffect();
    Flip();

    // Check landing impact for squish effect
    if (isGrounded && !wasGroundedLastFrame && !isWallTouch)
    {
        StartCoroutine(Squish());
    }

    // Store ground state for next frame comparison
    wasGroundedLastFrame = isGrounded;
    previousYVelocity = rb.velocity.y;
}

private void HandleMovement()
{
    moveX = Input.GetAxis("Horizontal");
    if (!isDashing)
    {
        if (moveX != 0)
        {
            // Apply movement
            rb.velocity = new Vector2(moveX * moveSpeed, rb.velocity.y);

            spriteRenderer.flipX = moveX < 0;
        }
        else
        {
            // Stop the player instantly when no input is detected
            rb.velocity = new Vector2(0, rb.velocity.y);


        }
    }
}

private void HandleJump()
{
    if (Input.GetButtonDown("Jump") && isGrounded)
    {
        rb.velocity = new Vector2(rb.velocity.x, jumpForce); // Set Y velocity to jump force
        isGrounded = false;
        animator.SetBool("isJumping", !isGrounded);
    }
    else if (isSliding && Input.GetButtonDown("Jump"))
    {
        isWallJumping = true;
        Invoke("StopWallJump", wallJumpDuration);
    }

    if (Input.GetButtonUp("Jump") && rb.velocity.y > 0)
    {
        // Reduce the upward velocity by 50% when the jump button is released
        rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
    }
}

void StopWallJump()
{
    isWallJumping = false;
}

private void Flip()
{
if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
{
isFacingRight = !isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
transform.localScale = localScale;
}
}

private void FixedUpdate()
{
    animator.SetFloat("xVelocity", Mathf.Abs(rb.velocity.x));
    animator.SetFloat("yVelocity", rb.velocity.y);

    if (isSliding)
    {
        rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -wallSlidingSpeed, float.MaxValue));
    }
}



private IEnumerator Squish()
{

    // Record the original scale
    Vector3 originalScale = transform.localScale;

    // Calculate the squished scale
    Vector3 squishedScale = new Vector3(originalScale.x + squishAmount, originalScale.y - squishAmount, originalScale.z);

    // Apply the squished scale
    transform.localScale = squishedScale;

    // Wait for the duration of the squish effect
    yield return new WaitForSeconds(squishDuration);

    // Revert to the original scale
    transform.localScale = originalScale;
}
private void HandleDash()
{ 
    if (Input.GetButtonDown("Fire3") && canDash) // "Fire3" is typically bound to Left Shift or a controller button
    {
        StartCoroutine(Dash());
    }
    if (isDashing && !Input.GetButton("Fire3"))
    {
        StopDash();
    }
}

private IEnumerator Dash()
{
    
    isDashing = true;
    


    if (!isGrounded)
    {
        canDash = false;
        hasAirDashed = true;
    }

    

    rb.gravityScale = 0; // Temporarily set gravity to zero for the dash

    Vector2 dashDirection = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

    if (dashDirection == Vector2.zero)
    {
        dashDirection = spriteRenderer.flipX ? Vector2.left : Vector2.right; // Default dash direction based on facing
    }

    rb.velocity = dashDirection.normalized * dashForce;

    

    // Keep dashing until the dash duration or until the button is released
    float dashEndTime = Time.time + dashDuration;
    while (Time.time < dashEndTime && Input.GetButton("Fire3"))
    {
        yield return null;
    }

    // Restore gravity and stop dashing
    StopDash();

    yield return new WaitForSeconds(dashCooldown);
    
    if (isGrounded)
    {
        canDash = true;
    }
                                                   
}

private void StopDash()
{
    rb.velocity = new Vector2(0, rb.velocity.y); // Stop horizontal movement
    isDashing = false;
    StartCoroutine(ImpactGravity());
}

private IEnumerator ImpactGravity()
{
    // Temporarily increase gravity
    rb.gravityScale = impactGravity;

    // Wait for the duration of the impact effect
    yield return new WaitForSeconds(impactDuration);

    // Restore original gravity
    rb.gravityScale = originalGravity;
    isDashing = false;
}

private void HandleStretchEffect()
{
    if (!isGrounded && !isWallTouch && rb.velocity.y < 0)
    {
        // Apply stretch effect while falling
        Vector3 newScale = new Vector3(squishFactor, stretchFactor, 100f);
        transform.localScale = Vector3.Lerp(transform.localScale, newScale, Time.deltaTime * stretchSpeed);
    }
    else
    {
        // Return to normal scale when not falling
        transform.localScale = Vector3.Lerp(transform.localScale, Vector3.one, Time.deltaTime * stretchSpeed);
    }
}
private void OnTriggerEnter2D(Collider2D collision)
{ 
    animator.SetBool("isJumping", !isGrounded);
}

any help would be appreciated

… except it isn’t.

Since the only clue we have is “player not jumping horizontally when walljumping,” the only thing we can say is,

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

If I am reading this correctly, when a wall jump occurs you set isWallJumping true and then the code in Update will set the desired wall jump velocity starting on the next frame for as long as isWallJumping is true. The horizontal velocity in this case requires the user to keep pressing the horizontal direction towards the wall for the duration of the jump.

However, HandleMovement() occurs after the code that sets the wall jumping velocity. If you are not dashing, then this code will override whatever wall jump velocity you were trying to set.

It may help to print out the rb.velocity at different places in update to see how it is changed by the Update code and the Handle* functions.

By the way, for future reference, there is a </> button in the post editor that you can use when posting code.

thank you, i have already tried that and found that it never changed my x velocity upon press of the space key