[FIXED] Inconsistent Jump Height with CharacterController-based Jumping Script

I’ve been working with this character controller that adjusts with Cinemachine camera movement and I wanted to create a jump script for the player to use, this is the following script I have:

But what I’m now having trouble with is that -

  1. I press my “Jump” key (in this case, space) and it doesn’t jump at all
  2. I do jump, but this can range from a small hop, all the way to a huge leap in the air

I had taken a break and come back after a few days and after looking over it with “fresher” eyes, my complications really just seem to come down to the keybind section (the main if statement). Is it possible this is an error in the frequency in which the Update() function is called? Any help is appreciated, as I’ve been stuck on this problem and other threads and videos I’ve looked at apply to a different kind of character controller and not the actual Character Controller component itself.

You can use [ code ] tags to share code here.

As for your issue, you’ve been accumulating gravity into the velocity non-stop since you started the game. Your jump has basically no chance of overcoming that force unless you bounce like a rabbit the entire time you play. Instead of adding to the velocity with +=, explicitly set the velocity with = when you jump.

Thank you for both the help and the tip about sharing code, the problem is fixed!

Be careful you are not calling .Move() twice per frame or you may have issues with sensing IsGrounded.

CharacterController CharMover broken:

I wrote about this before: the Unity example code in the API no longer jumps reliably.

I reported it in October 2020. Here is a work-around: