# Unity 2D: Inconsistent jump height in game window

Whenever I start the unity editor and play it in the Game windows, sometimes the object can jump higher sometimes it is just small jump. I didn't change any value in my script nor changed it in inspector window.

It usually happens when I restart the unity editor or having my computer shutdown / restart and reopening the project.

Here are the jump code

void jump() {
if (isInGround) {
float currentJumpForce = jumpForce * Mathf.Abs(rigidBody.velocity.x) / 3.53f;
animator.SetTrigger("isJump");
}
}


I place the code inside the FixedUpdate method, for what I have read the physics calculation should be inside FixedUpdate right?

private void FixedUpdate() {
if (Input.GetKeyDown(KeyCode.UpArrow)) {
jump();
}
}


I have read many are having similar problem, but it really doesn't answer this question.

UPDATE:

I forget to explain it in the question. The jumpForce is calculated based on the velocity of the gameObject has. I capped the velocity to certain speed based on this code

void accelerate() {
if (rigidBody.velocity.x <= maxSpeed) {
}
}


where maxSpeed is a constant. I know this is probably not the accurate way to cap the velocity, or is it? Maybe this is where it gets messed up?

I just kinda assume the velocity is the capped from the camera movement and the 'display' or the movement of the screen. It seems the same to me.

• Seems like currentJumpForce calculation depends on rigidBody.velocity.x, which means the faster the object is moving to the +x or -x axis, the higher the object will jump. Is there a reason for this? Is it a game feature? – TomTsagk Aug 22 '18 at 13:10
• @TomTsagk yes it is indeed a feature. I'm sorry for not explaining that before. But I'm sure I had capped the velocity to certain speed, and when I tested it when it reached it's limit. I'll try to update the question then – otong Aug 22 '18 at 15:11