1
\$\begingroup\$

I've got a very annoying problem that I have been stuck on for a few days and I can't figure it out.

It is for a wall jump.

I basically want my wall jump to have a bit of force away from to wall to make it look and feel better than just jumping up straight.

The problem is, when i add a force on the x axis, it does not register when i am also holding the arrow towards the wall. If I am not holding down the walking button, then press jump...then the x force works.

I have a feeling that the horizontal axis force is competing with the opposite force that i want to add to the player when he hits the jump button...

Walking code:

private void ApplyMovement()
{
    if (isGrounded)
    {
        myRigidbody.velocity = new Vector2(movementSpeed * movementInputDirection, myRigidbody.velocity.y);
    }
    else if (!isGrounded && !isWallSliding && movementInputDirection != 0)
    {
        Vector2 forceToAdd = new Vector2(movementForceInAir *  movementInputDirection, 0);
        myRigidbody.AddForce(forceToAdd);

        if (Mathf.Abs(myRigidbody.velocity.x) > movementSpeed)
        {
            myRigidbody.velocity = new Vector2(movementSpeed *  movementInputDirection, myRigidbody.velocity.y);
        }
    }
    else if (!isGrounded && !isWallSliding && movementInputDirection == 0)
    {
        myRigidbody.velocity = new Vector2(myRigidbody.velocity.x * airDragMultiplier, myRigidbody.velocity.y);
    }

    if (isWallSliding)
    {
        if (myRigidbody.velocity.y < -wallSlideSpeed)
        {
            myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, -wallSlideSpeed);
        }
    }
}

Jump code:

private void Jump()
{
    if (canJump && !isWallSliding)
    {
        myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
        numberOfJumpsLeft--;
    }
    else if ((isWallSliding || isTouchingWall) && !isGrounded && canJump)
    {
        isWallSliding = false;
        numberOfJumpsLeft--;
        Vector2 forceToAdd = new Vector2(wallPushForce * -facingDirection, wallJumpForce *
                                         wallJumpDirection.y);
        myRigidbody.AddForce(forceToAdd, ForceMode2D.Impulse);
    }
}

Where I call The code:

void Update()
{
    CheckInput();
}

private void FixedUpdate()
{
    ApplyMovement();
}

private void CheckInput()
{
    movementInputDirection = CrossPlatformInputManager.GetAxisRaw("Horizontal");

    if (Input.GetButtonDown("Jump"))
    {
        Jump();
    }

    if (Input.GetButtonUp("Jump"))
    {
        myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, myRigidbody.velocity.y * variableJumpHeightMultiplier);
    }
}

Any help would be much appreciated.

Thanks in advance

\$\endgroup\$
  • \$\begingroup\$ Presumably you tried disabling or dampening air steering into the wall for a period of frames after initiating a wall jump? How did that work out? Don't forget to show us where these two methods are called! \$\endgroup\$ – DMGregory May 7 '20 at 11:24
  • \$\begingroup\$ I have updated the post to reflect where I call the code. I am not sure how to disable the steering while wall jumping and turning it back on. I will play around and see if I can figure it out. \$\endgroup\$ – Remy Limelight May 7 '20 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.