Jumping sometimes doesn't jump

Hello everyone,

I’ve working on physics platformer, and I’ve set up some basic jump logic for my character, but strangely, sometimes it just simply doesn’t jump. 90% of the time, it works, but every now and then it just doesn’t do anything.

I figured it was probably because I’m using addforce, and so if the player is falling, then adding a force would basically be added to a negative on the Y and it wouldn’t have any net force. So I included a velocity reset on the Y right before the jump, so that all jumps would have net force. But it’s still being a bit fickle. Here is the simple code I’m using, Any thoughts?

OH, and this code is inside of the FixedUpdate function. (and rb is a rigidbody)

// Jump Code
		if (Input.GetButtonDown("Jump"))
			// resets the Y velocity so the jump is more consistent
			rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
			// adds a force to jump the ball, based on the angle of what you're standing on
			rb.AddForce(platformNormal * jumpPower, ForceMode.VelocityChange);


DERP. I put this code into the normal Update function and now jump works 100% of the time… That was silly of me >.<

I’ll keep this here JUST in case anyone else makes the same mistake as me.

@Sussy It is better to get input in update and make use physics in fixed update so try something like this instead:

bool jumped = false;


   jumped = true;

     jumped = false;
     //now add the jump code here;