Incrementing one time in fixed update

Hello! I want my character jumps higher and higher after each of his jumps.

His jumps are based on physics, so I use a Fixed Update for make him jump. But i want my script to increment one time a value after that the avatar has jumped.

It’s possible to incrementing just one time in fixed update? If yes, how i do?

there is the script I use in the fixedupdate to make my avatar jump (and the value numberjump is the one i want to increment one time by jump):

         if ((canjump == true) && (Input.GetButton ("Jump")))
         {
             Vector3 up = new Vector3 (0.0f, upper, 0.0f); // script for jumping
             rb.AddForce (up * upper);
             numberjump++;
         }

You’re using Input.GetButton(), which will return true as long as the button is held down - this is not how jumping is usually handled. Replace it with Input.GetButtonDown(), which will only return true on a single frame when the button is first pressed.

Apart from that, the code as you have it now does exactly what you want, at least if “numberjump” is a field variable. It’s a bit strange that you first define the vector “up” with “uppper” as its y length, and then multiply it by “upper” again, but apart from that it looks fine. You’re not doing anything with the “numberjump” variable yet though, so you obviously won’t jump higher after each jump (unless you change the “upper” variable somewhere else).

Ok thank! I’ll try that!

And yes, i do something with “numberjump” ;D : for jumping higher, i use the variable "numberjump " in the update function where I use a condition.

If (numberjump == 1)
{Upper =19.0f;
}
If else (numberjump ==2)
{Upper = 25.0f;
}

Etc. … so the player normally jump higher! :slight_smile: (sorte if m’y english is bad, im learning from not long…)

You shouldn’t have that in the Update loop. You will only change the numberjump variable when you jump, so checking against this value every frame is a waste of processing power. A very, very small amount of processing power, but it’s not necessary nonetheless, and it makes your code less readable.

A proper way of doing this would be either defining a formula with a asymptote that increases the jump power (but doesn’t go over a predefined value so you can’t jump infinitely fast), or defining a predefined set of jump powers in an array. You can then use the numberjump variable to pick the correct jump power from that array directly. You only need to check what power to jump with in the part of your code where you add the jumping force (inside the Input.GetButtonDown() condition).

Okay! but i’m new in programming and i don’t know what is a formula with a asymptote. Can you please show me an example of that? ^^

I don’t know what is an array but i’ll see some tutorials for learning, thanks! :slight_smile: