Hold Spacebar for higher jump

When you press the Spacebar, the character needs to jump like 1 high.
If you hold the Spacebar for 3 seconds the character needs to jump 3 high, after you release the Spacebar.
If you hold the Spacebar for like 2.5 seconds the character needs to jump 2.5 high, after you release the Spacebar.
And so on…

Can anyone help me? Any tips are welcome

on SpaceBar Down :
switch to an “accumulating jump power state” and reset jump power variable.

every frame :
if in “accumulating jump power state”, increment a jump power variable (with Time.deltaTime for example).

on SpaceBar Up :
look at your jump power variable and map it mathematically to your jump power. And Jummmmp ! :slight_smile:

The 2d tutorial in unity examples teach you how to do this. Check the tutorials and examples there.

Make a count… While holding space bar down, count increases. When you release, use the count as a power factor.

2 Likes

Make sure to multiply the “added” count by the deltaTime, for consistency.

in theory you can cheat but reducing gravity while the space bar is down (and have player jump). Releasing space bar switches gravity back to original. Just a thought. :slight_smile:

Ok so I get it… But how do I multiply the “added” count by the deltaTime?

The following code is what I’ve got so far:

var Counter : int = 0;

function Update () {

if (Input.GetKeyDown (“space”))
Counter++;

if (Input.GetKeyUp (“space”))
print (“Jump”);

}

Thanks for all the help so far!

you have to search related to spacebar counter you have to se the best result that one of them go to the site and get some ideas…