Hi, just making this thread so I don't interrupt the other person asking for help!
I fixed the jump, thank you guys so much for the advice! Mostly I'm just coming back because I'm just not sure if I did it in a very good way. Turns out it was calling the coroutine twice because you are grounded through 2 fixed updates, and the way I fixed that was by adding a "isJumping" bool that activates here:
if (Input.GetKey(KeyCode.Space) && isGrounded && !isJumping)
{
Debug.Log("Blast off!");
isJumping = true;
StartCoroutine(Jump());
}```
and turns off here:
```c#
private IEnumerator Jump() {
//body.AddForce(new Vector2(0, jumpHeight*5), ForceMode2D.Impulse);
float cooldown1 = 1;
while (Input.GetKey(KeyCode.Space) && cooldown1 > 0) {
body.velocity = new Vector2(body.velocity.x, 10 + -3*(cooldown1 - 1)); //.998 - 1 = -.002
cooldown1 -= Time.deltaTime;
yield return null;
}
isJumping = false;
}```
Is this the most elegant solution, or is there a better way to prevent the second execution that i'm just not seeing? By the way, thank you guys so much for mentioning the issue with the yield outside the while loop; that entirely fixed the issue with the variable jump length not working, I just need to tune the values now!
To be clear, everything works now, this is just asking what would be the best style/approach/syntax for this problem so my code is cleaner and causes less problems later. If there is a better solution that will just require some research, just throw a link down :)
P.S.: This is an unrelated question, but I read somewhere that it's better to have Inputs within Update() and any physics-based movement within FixedUpdate(). Should I refactor my code so that's how it works, or is it more or less negligible?