Variable jump height

void Update()
    {
        
        
        isGrounded = myFeet.IsTouchingLayers(LayerMask.GetMask("Ground"));
        
     
        Jump();

        if(jumpTimer > 0) jumpTimer -= Time.deltaTime;


        if (isGrounded && jumpTimer <= 0){
            coyoteTimer = maxCoyoteTimer;
            
        }

        
        if (coyoteTimer > 0) coyoteTimer -= Time.deltaTime;
        if (jumpBuffer > 0) jumpBuffer -= Time.deltaTime;
    }


void OnJump(InputValue value){
        jumpInput = value.isPressed;
        
        jumpBuffer = maxJumpBuffer;
        }


void Jump(){
        if (coyoteTimer > 0 && jumpBuffer>0 ){
                coyoteTimer = 0;
                jumpBuffer = 0;
                jumpTimer = jumpCooldown;
                myRigidbody.AddForce(new Vector2(0,jumpForce*100));
                
        }
    }


Here’s my script. The solution that i have in mind is to use a timer and when jumpInput = true, I start the timer. Then if the timer reaches a maximum amount, I stop adding force.
I just dont know how to fit that with my coyote timer and jump buffer.

Basically the coyote timer allows to jump a split second after not touching ground
and jump buffer allows to press jump a split second before touching ground

Hi,

Your code looks promising so far. However, I would recommend to start with one timer and make it work first. Then add the other timer. If you implement both without knowing that at least one timer works as expected, the problem becomes even more complex.

Ive tried but now ive run into another problem. The ‘jumpInput’ bool doesnt turn false even when i stop pressing the jump button

Why do you expect jumpInput to become false when presing the jump button? Have you checked the value of value.isPressed in OnJump?

No i expected it to turn false when Im not pressing it. I guess it doesnt work that way in the new system. Ive found the solution tho.
For anyone reading this in future, you need to use

[SerializeField] InputActionReference nameOfAction;

//Then in your function use
nameOfAction.action.inProgress
//This will give true if button is pressed

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms