C
C#10mo ago
Braisie

✅ Can't stop multi jumping, Please Help

public LayerMask groundLayer; private bool isGrounded; public Transform feetPosition; public float groundCheckCircle; public float jumpTime = 0.35f; public float jumpTimeCounter; private bool isJumping; // Start is called before the first frame update void Start() {
} // Update is called once per frame void Update() { input = Input.GetAxisRaw("Horizontal"); if (input < 0) { spriteRenderer.flipX = true; } else if (input > 0) { spriteRenderer.flipX = false; } isGrounded = Physics2D.OverlapCircle(feetPosition.position, groundCheckCircle, groundLayer); if (isGrounded == true && Input.GetButtonDown("Jump")) { jumpTimeCounter = jumpTime; playerRb.velocity = Vector2.up * jumpForce; } isJumping = true; if (Input.GetButton ("Jump") && isJumping == true) { if(jumpTimeCounter > 0) { playerRb.velocity = Vector2.up * jumpForce; jumpTimeCounter -= Time.deltaTime; } else { isJumping = false; } } if (Input.GetButtonUp("Jump")) { isJumping = false; }
No description
10 Replies
Keswiik
Keswiik10mo ago
You'll probably get more traction on this in #game-dev , but why are you always setting isJumping = true in your Update method? What is the intended purpose of jumpTime and jumpTimeCounter? Setting isJumping = false when you let go of the jump button likely isn't doing anything meaningful since you set it to true during every update anyways.
Braisie
BraisieOP10mo ago
jumpTime and jumpTimeCounter are the reset time in which the jump key can be used again and okay thanks I'll have a look👍 😃
Keswiik
Keswiik10mo ago
With the way you've written this, it looks like it'll let you continually jump so long as you're holding space, at least until jumpTimeCounter runs out.
Braisie
BraisieOP10mo ago
Sorry if I suck at explaining this haha, just started today 🙂 Currently I can't hold it forever but I can keep spamming it for jumps
Keswiik
Keswiik10mo ago
I didn't say forever, I said you can hold it until jumpTimeCounter runs out. Spamming it works longer because you only decrement jumpTimeCounter on frames where the jump button is pressed.
Braisie
BraisieOP10mo ago
Oh crap yeah I get what you mean Yeah thats 100% whats happening
Keswiik
Keswiik10mo ago
If the intent is to only let people jump when they are grounded, you probably need to manage your player state better. isJumping could be entirely removed and nothing would change because you've hardcoded it to be true during every frame.
Braisie
BraisieOP10mo ago
That's true haha, been following an online tutorial for this but you've helped explain much better 👍 thank you very much for the help
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX10mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server