implementing a wall jump

Hey folks, I’m trying to make a wall jump mechanic in 2D, so far I have the player clinging to the wall if I hold the directional button down, I want to press the jump button while I do that, and have it ignore the directional input and do the jump arc.

This is what I have so far:

void wallClingingFun()
    {

        rb2d.velocity = new Vector2(0, 0f);

        wallCling = true;
        doubleJump = true;

        if (Input.GetButtonDown("Jump"))
        {
            wallCling = false;

            if (facingRight)
            {
                facingRight = !facingRight;
                rb2d.velocity = new Vector2(-25, 7);
                wallJump = true;
            }
            else if (!facingRight)
            {
                facingRight = !facingRight;
               rb2d.velocity = new Vector2(25, 7);
                wallJump = true;
            }
        }

obviously, it’s not working, and I’m not sure what the correct functions I should use to make it work.

Any ideas?

Instead of using a ‘velocity’ function, try adding force to the rigidbody. When creating a basic jump function the ‘AddForce’ is commonly used :slight_smile:

Example Script:

rb2d.Addforce(transform.right * 30, ForceMode.Force);

And when jumping left you just put a “-” before the “transform.right” to jump in the opposite direction :slight_smile:

rb2d.Addforce(-transform.right * 10, ForceMode.Force);

This may or may not be a functional script but I suggest you google about adding force to a side direction and also experiment yourself!