So when i had all of my code in Update everything was working fine but after i moved the physics to fixedUpdate it broke. Here is my code
private bool Jump;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// Check if space key is pressed down
if (Input.GetKeyDown(KeyCode.Space) == true)
{
Jump = true;
}
}
// fixedUpdate is called once every physic update
private void fixedUpdate()
{
if (Jump)
{
GetComponent<Rigidbody>().AddForce(Vector3.up * 3, ForceMode.VelocityChange);
Jump = false;
}
}
Apart from the fact that FixedUpdate is not spelt correctly, there’s no reason whatsoever to do this acrobatics with the boolean. You can apply one-time forces in Update without any problems. It doesn’t make any difference. Instead of creating a boolean member variable, you should create a “Rigidbody” variable which you initialize in Start / Awake instead of using GetComponent each time^^.
If you do the jump force in Update without a boolean or cooldown you might end up applying multiple jump forces in the same physics update, especially when running at high FPS.
If the user manages to click at a rate that is greater than 50Hz, then yes. Though this is almost impossible. While there are wild claims of records that people achieved 1000+ clicks in 10 seconds, it’s very unlikely that this is true. Most hardware would not even support such high rates. Default USB only polls at 120Hz. Depending on the mouse, if only the current state is polled, you could only achieve 60Hz when you are in perfect sync with the polling frequency. Insane progamers can achieve up to 15 clicks per second. Even when you double it, it would still be under 50 Hz. So, no, it’s pretty impossible to jump twice in between two physics frames.
Of course depending on the jumping mechanic you usually want to do a ground check anyways, otherwise you can jump in mid-air.