Diagonal Jump off Wall

Hey there!
I am trying to create a 3D Metroidvania in Side view. But now, I’ve come across a problem: I cant seem to figure out how to make a diagonal wall jump.

The wall jump itself works, but the player is able to jump straight up. I want to make a diagonal jump, so the player kind of launches away from the wall.

Here’s the jump script I got:

private void Jump()
{
    if (isGrounded)
    {
        if (coyoteTimeCounter > 0)
        {
            rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
            jumpBufferCounter = 0;
        }
    }
    else if (isWallJumping || (isWalled && !isGrounded))
    {
        if (hitRightWall)
        {
            Debug.Log("Right Wall Jump");
            rb.velocity = Vector3.zero; // Reset velocity before applying forces
            rb.velocity = new Vector3(-pushForce, jumpForce, 0f); // Apply diagonal force away from right wall

            isWallJumping = false;
            return;
        }
        else if (hitLeftWall)
        {
            Debug.Log("Left Wall Jump");
            rb.velocity = Vector3.zero; // Reset velocity before applying forces
            rb.velocity = new Vector3(pushForce, jumpForce, 0f); // Apply diagonal force away from left wall

            isWallJumping = false;
            return;
        }
    }
}

Its probably more complicated than it needs to be for a simple jump script, but I tried, and didn’t succeed.

Maybe you can help me?

pretty please

I’m going to speculate that your problem is with how you handle horizontal movement outside of the code you have posted. In your walljump code you are setting the X velocity that you want, but probably the horizontal movement code is overriding this value almost immediately.

If you want the wall jump’s horizontal velocity to be noticeable, I can think of two options.

  1. Set a short timer after a walljump occurs. During this timer, ignore the player’s horizontal input.
  2. Use acceleration to change the player’s horizontal velocity. If the player can’t change velocity instantaneously, then you’ll see some of the wall jump’s horizontal velocity before the player is able to overcome it.