A CharacterController's physics are processed during FixedUpdate().
With that in mind, you’re currently reliant on lucky timing based on the way you’re processing those physics.
So, let’s start with how you’re handling Jumping in the first place:
if (Input.GetButtonDown("Jump") && canCrouchUp)
{
Jumping();
}
else
{
gravityVector.y = gravityForce;
}
// ... and...
void Jumping()
{
// ...
gravityVector.y = jumpForceMultiplier;
}
First, let’s compare Update() to FixedUpdate(). Update() runs as rapidly as possible/is permitted (i.e. limited by Vertical Sync), where FixedUpdate() only runs at a fixed pace (by default, 50 times per second).
Based on your script, this means that it’s a race. After the Update() cycle where you provide input, will FixedUpdate() take place and process the instructions given to the CharacterController, or will the next Update() run and reset “gravityVector.y” to the “gravityForce” value again?
With a lower framerate (60, for instance), Update() can run twice in a row without a FixedUpdate(), but it’s a 1/6 chance to occur. By contrast, with a framerate of 500, you would have only a 1/10 chance of your “Jumping()” function’s impact on gravityVector being reflected by the physics interactions.
(As another element of this…
isGrounded = Physics.CheckSphere(transform.position - new Vector3(0f, 0.56f, 0f), 0.5f, groundedLayers); //CheckSphere to know when player is and isn't Grounded.
… would be run again before you have a chance to move, resulting in the assumption you’re on the ground and, therefore, negating the change to “gravityVector”)
Finally, in addition to all this, you’re mixing up your [position-by-gravity] and [acceleration-by-gravity] formulas, resulting in a somewhat irregular gravitational formula:
// After 1 second, vertical speed would be (gravityForce^2)
// After 2 seconds, vertical speed would be (2 * gravityForce^2)
// After 3 seconds, vertical speed would be (3 * gravityForce^2)
// And so on...
gravityVector.y -= gravityForce * gravityForce * Time.deltaTime;
// After 1 second, vertical speed would be (gravityForce)
// After 2 seconds, vertical speed would be (2 * gravityForce)
// After 3 seconds, vertical speed would be (3 * gravityForce)
// And so on...
gravityVector.y -= gravityForce * Time.deltaTime;