Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ilovetoeatmeatballs · May 31, 2021 at 04:32 PM · scripting problemunity 2djump

Jump buffering and Coyote time causes double jump when spamming jump

I implemented jump buffering and coyote time but when I spam the jump button, the player can do a double jump. How do I fix it?

 //Ground Check
 bool isGrounded;
 float groundedRemember = 0;
 float groundedRememberTime = .1f;

 //Jump
 public float jumpForce;
 float jumpPressedRemember = 0;
 float jumpPressedRememberTime = .2f;

How I code jump buffering and coyote time:

     if ((jumpPressedRemember > 0) && (groundedRemember > 0))
     {
         rb.velocity = new Vector2(rb.velocity.x, jumpForce);
         jumpPressedRemember = 0;
         groundedRemember = 0;
     }

     jumpPressedRemember -= Time.deltaTime;
     if (Input.GetKeyDown(KeyCode.Space))
     {
         jumpPressedRemember = jumpPressedRememberTime;
     }

     groundedRemember -= Time.deltaTime;
     if (isGrounded == true)
     {
         groundedRemember = groundedRememberTime;
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Artik2442 · Jun 01, 2021 at 10:01 AM

I have only 2 explanations:

1) Your isGrounded bool doesn't change to false until you press the space bar a second time.

2) You pressed the space bar so fast that before isGrounded variable has changed, you had the time to double jump.

The most probable one is the first explanation. Set isGrounded to public to see in your inspector when it changes, if it changes correctly or not.

By the way, what do you use to check ground collision?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ilovetoeatmeatballs · Jun 03, 2021 at 02:36 PM 0
Share

I checked and the isGrounded bool changes to false as soon as the player leaves the ground. I think the problem here is jumping will trigger the coyote time so after you jump, the script will still tell you you are on the ground and allow you to jump again. I use overlapbox to check ground collision.

avatar image
0

Answer by GuirieSanchez · Nov 14, 2021 at 12:39 PM

Hi @ilovetoeatmeatballs , did you find the solution to that? It also happened to me when I set the jumpcooldown to a low number (something like 0.15 and below. So the problem might be what you've said: jump buffering and coyote time interacting with each other.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zaidan1193 · May 18 at 08:04 PM 0
Share

Found a fix but its not really the best, I created a Ienum and put a cooldown after the player jumps for the coyote time value + 0.01, put a boolean that must be true for the player to jump and set it to false until the timer finishes, once the timer finishes its goes back to true and the player can jump. Its not the best fix to be honest, but it works for now. I'll come back here if I ever find a better alternative.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

222 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 2D Enemy jump Question (Frog jump) 1 Answer

Unity2d move enemy in opposite direction on collision 1 Answer

Error: An object reference is required to access non-static member, help? 2 Answers

UI Jump Button - I want to click on the button to jump but instead I jump when I click anywhere on the screen. 0 Answers

Increase enemy speed when it sees the player 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges