I’m working on my jump physics for my 3rd Person Adventure game and so far the jumping works fine. I hit space the player jumps, but what I am looking for is to make him jump like Mario, with variable jump heights.
I’ve followed some tutorials and had it working for a bit but after I’ve re-organized my inputs into Update and took them out of FixedUpdate, I ran into problems.
Looking for a solution to this and get my player jumping based on how long the button is being held down. So far I’m using the JumpTimeCounter technique that sets a timer to see how long the button is held. Also, I’m trying to get him to only jump once, despite the button being held down.
I should say that if you are going to add this to a more complex physics scene it would be a good idea to flag a jump as being required from the GetButtonUp and then check for it and apply the force in FixedUpdate. Whilst the previous code will work, it is good practice to apply forces in FixedUpdate, not Update.
What I ended up doing instead was putting all of the JumpTimeCounter stuff in with the GetInput Function and it works perfectly. As you hold space, it adds +1 to the Counter and when it gets equal to the set JumpTime, it returns the jump false and resets the counter to 0.