Scripting Double Jump problems

Hello all.

I’d like to ask about double jumping here. Now, I know it’s more about letting you do jump twice. However, when the game object is descending, the double jump force gets lessened, weaker than when I just tell the object to jump before it started descending. I want to make a consistent double jumping. Here’s my code so far for jump:

if (stateJump)
rigidbody2D.addForce(new Vector2 (0, 200*Time.deltaTime));

(stateJump being a state where it’s OK to jump, like if you press up arrow.)

Where do you think I go wrong?

Thanks for the advice.

You need to add force proportional to the existing vertical force, alternatively just set set the vertical speed directly.

Well I could use some help in doing that. I’m very much a newbie in that.

Right now I didn’t do anything to the gravity force.

Don’t use delta time on physics, just do the physics in the fixed update

for jumping.

//Get the rigidBody component
RigidBody myRigidBody = GetComponent<RigidBody>();
//Set a jumpHeight variable
public float jumpHeight = 10f;

myRigidBody.velocity = Vector3.up * jumpHeight;

That works wonders. Another alternative is everytime you jump, you set your y velocity to 0 first before adding force.

Should velocity fall into Fixed update too?

Yes. But velocity fall is based on gravity. So, you let physics do it thing with gravity (or just give more force to the gravity itself), or you can disable gravity and manage yourself the falling.