Jump Mechanics

I originally had some code from a video to do the “Mario Jump Mechanic” It was able to work when I used the Space bar key, but when when I duplicate it, and change the other script to work with the W key, I have to press both of them to work.

Original code:

if (characterRigidBody.velocity.y < 0)
{
    characterRigidBody.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
}
else if (characterRigidBody.velocity.y > 0 && !Input.GetKey(KeyCode.Space))
{
    characterRigidBody.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
}       

New code:

if (characterRigidBody.velocity.y < 0)
{
    characterRigidBody.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
}
else if (characterRigidBody.velocity.y > 0 && !Input.GetKey(KeyCode.Space))
{
    characterRigidBody.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
}
else if (characterRigidBody.velocity.y > 0 && !Input.GetKey(KeyCode.W))
{
    characterRigidBody.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
}
else if (characterRigidBody.velocity.y > 0 && !Input.GetKey(KeyCode.UpArrow))
{
    characterRigidBody.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
}

I have no idea of your intentions here and code provided is barely any help but the first thing you should do to make your life easier is to simplify this code:

bool inputUp = Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);

if( characterRigidBody.velocity.y==0 )
{
    // character is not moving vertically
}
else if( characterRigidBody.velocity.y<0 )
{
    // character is moving down

    characterRigidBody.velocity += Physics2D.gravity * (fallMultiplier - 1) * Time.deltaTime;
}
else if( characterRigidBody.velocity.y>0 )
{
    // character is moving up

    if( !inputUp )
    {
        characterRigidBody.velocity += Physics2D.gravity * (lowJumpMultiplier - 1) * Time.deltaTime;
    }
}

As I mention before - this is just a cleanup after spaghetti code and this code still doesn’t make sense to me.

Thanks! It worked. I think what helped was the bool.