How to make different jump heights with different press duration

Hello! I broke my head trying to solve this problem. What needs to be added to the Rick’ code to make it work?

Hi Igor,

What exactly do you mean by “different press duration”?

If you want to check how long the player keeps pressing a button/key down, you could keep track of the elapsed time with a variable of type float to which you add Time.deltaTime each frame while the key/button is being pressed down.

And when the player releases the button/key, your code checks the value of the float variable.

Did this help? :slight_smile:


See also:

I need the height of the jump to be adjusted to the space bar depending on how long I hold it. For example, I press on “space” a little and the character jumps a little:) sorry for my English, I’m russian. I understand English when I listen or read, but it’s such difficult to write something:)

I tried using Input.GetButtonUp, but the character behaved inappropriately or my player has two jumps: when I press the button and when I release the button. When I add Time.deltaTime he stopped jumping at all. Other solutions on the internet completely change the jump code. I’m wondering if it’s possible to add something to the Rick’s code. My code turned to mess after all my experiments and I just delete all mistakes. I just stared on the screen and don’t know what to do. Maybe this problem solves by the one string, but I’m stuck in the unbreakable wall.

Where did you add Time.deltaTime? I meant something like this. Depending on the value of fire_start_time, you could multiply a value to Rick’s “jump” velocity.

Problem
Uploading: Problem.PNG…
Something like that? but player doesn’t jump. Or Time.deltaTime must be in void Update?

Problem 2
If I add Time.time It’s still doesn’t work :frowning:

I’ve just noticed that the linked example doesn’t show what I meant.

I meant something like this:

elapsedTime += Time.deltaTime;

Take a pen and a sheet of paper and visualise your concept. That’ll help you translate your idea to code and to implement it in Unity.

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

Privacy & Terms