Hey guys,
I downloaded the Sample Assets beta, which has a jump script that looks like this:
// If the player should jump...
if (grounded && jump) {
// Add a vertical force to the player.
anim.SetBool ("Ground", false);
rigidbody2D.AddForce (new Vector2 (0f, jumpForce));
}
}
And I personally added the following to add a double jump:
else if (grounded == false && jump && doubleJumpCount == 1) {
rigidbody2D.AddForce (new Vector2 (0f, doubleJumpForce));
doubleJumpCount = 0;
}
if (grounded) {
doubleJumpCount = 1;
}
}
Now first off, I’m kind of a newbie so I’m fairly proud this worked out in general. But is this clean code or is there a better way to do this?
Now, to my actual question:
Currently the second jump is affected by the first jump’s velocity. So if I double jump really quick in succession, the character goes a lot higher than when i jump, wait a bit, and jump again.
How can I change this so when the double jump button is pressed, the character basically loses all the momentum he has and the double jump always has the same height?
I tried adding
rigidbody2D.AddForce (new Vector2 (0f));
Into the double jump function, but got an error.
Thanks in advance!