• 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 /
avatar image
0
Question by Epicnez · May 18, 2020 at 06:24 PM · 2dinputjumptimerjumping

Coyote Time/Ledge Assistance Causes Double Jump

Hello! Thank you for reading! If you don't know coyote time/ledge assistance is when the player has a short amount of time to jump after leaving the platform they are on. This is how I am doing it:

First I define a float called groundedRemember.

 public float groundedRemember = 0;

Then in Update() I subtract Time.deltaTime from it.

 groundedRemember -= Time.deltaTime;

Also in Update() I check if the player is grounded, if so, I set groundedRemember to 0.25.

if (grounded)

         {

             groundedRemember = 0.25f;

         }


Then if the player jumps and all the conditions are true (jumpPressRemember is for a jump buffer, and topChecker is to make sure there is nothing above the player) then make the player jump, making sure to reset the groundedRemember timer.

 if ((jumpPressRemember > 0) && groundedRemember > 0 && !topChecker.GetComponent<TopChecker>().touching)
 
         {
 
             jumpPressRemember = 0;
             groundedRemember = 0;
             Debug.Log("Jamp");
             playerRb.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
             jumpSound.Play();
 
         }

The problem is if the player spams jump they are double jump for a split second. I thought resetting the timer would fix this but it does not. Why is this occurring? I can upload more details if necessary. Thank you again! Any help is appreciated!

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Epicnez · May 19, 2020 at 01:03 AM

@unity_ek98vnTRplGj8Q Thank you for the code snippet, the only thing that had to be changed in order to work was in the last if statement: if(jumpTimer > 0 && blah blah blah){ jumpTimer = jumpCooldown; //All your other stuff } The part that says jumpTimer > 0, should be groundedRemember > 0, or else the player will not be able to able to jump at all. Thank you so much again! It worked perfectly!

Comment
Add comment · 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
2

Answer by unity_ek98vnTRplGj8Q · May 18, 2020 at 08:57 PM

My guess is that you are setting the groundedRemember to 0 during the initial jump, but then the following Update frame your player has moved so little that it is still detected as being grounded and groundedRemember gets set straight back to 0.25. This will depend on a lot of things, like framerate and how exactly you are checking if the character is grounded. I recommend adding a short jump cooldown (during which groundedRemember is not set to 0.25).

Comment
Add comment · Show 2 · 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 Epicnez · May 18, 2020 at 10:08 PM 0
Share

@unity_ek98vnTRplGj8Q I am checking if the player is grounded using this line of code:

     grounded = Physics2D.OverlapBox(playerFeet.transform.position, new Vector2(.72f, .16f), 0, groundLayers);

If I replace this:

 if (grounded)
 
      {
 
          groundedRemember = 0.25f;
 
      }

With this:

      if (grounded)
 
     {
 
         StartCoroutine(GroundedCoolDown());
         
     }
 
     public IEnumerator GroundedCoolDown()
 
     {
 
         yield return new WaitForSeconds(.1f);
         groundedRemember = 0.25f;
 
 
     }

Unfortunately this does not fix the problem. It seems that the player can double jump for 0.25 seconds after jumping, I think this because that is the amount the groundedRemember float is set to. Thank you for your help!

avatar image unity_ek98vnTRplGj8Q Epicnez · May 18, 2020 at 10:16 PM 0
Share

You are still setting groundedRemember to 0.25 the next frame, this code just delays it by a tenth of a second. I was thinking of something more like this

 public float jumpCooldown = 0.1f;
 float jumpTimer = 0;
 
 void Update () {
 
     if(jumpTimer > 0) jumpTimer -= Time.deltaTime;
 
     if (grounded && jumpTimer <= 0) {
         groundedRemember = 0.25f;
     }
     
     if(jumpTimer > 0 && blah blah blah){
         jumpTimer = jumpCooldown;
         //All your other stuff
     }
 }
avatar image
0

Answer by Epicnez · May 19, 2020 at 01:03 AM

@unity_ek98vnTRplGj8Q Thank you for the code snippet, the only thing that had to be changed in order to work was in the last if statement: if(jumpTimer > 0 && blah blah blah){ jumpTimer = jumpCooldown; //All your other stuff } The part that says jumpTimer > 0, should be groundedRemember > 0, or else the player will not be able to able to jump at all. Thank you so much again! It worked perfectly!

Comment
Add comment · 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
0

Answer by adscomics · Sep 23, 2020 at 05:35 AM

Just wanted to say that this helped me a TON. I was tearing my hair out figuring out how to solve this issue. Thanks @unity_ek98vnTRplGj8Q for answering the question, and thank you @Epicnez for asking it! I was worried this issue would be really niche.

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

291 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 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

Super Ghouls 'n Ghosts style jumps & double jumps? 1 Answer

Input.GetButton not working 1 Answer

Im trying to make it so it limits jumps in my 2d game. But when I play it, It only jumps once then your not able to jump again. Anyhelp? I need a answer fast because this is for the blackthornprod game jam 2 Answers

Advice needed on my first c# 2D jump script 1 Answer

Playerobject makes weird "jump" 1 Answer


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