Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 cjf420 · May 15, 2020 at 03:53 AM · 2d-platformerjumpinggroundground detection

How to deal with grounded check after jump initiated?

Hi, I'm looking for some advice on how to handle a scenario I've run into involving jumping and grounded checks.

Some quick background - I'm working on a 2D platformer and I'm fairly new to Unity, but I'm an experienced developer and I know C# well.

I'm using a RigidBody2D on my player entity. I am using two raycasts to determine if the player is grounded, basically one on each side of the player sprite.

I have numerous custom Monobehaviors attached to the player. One holds some state info, like "isGrounded", "isJumping", etc... and the others are for handling the different types of actions the player can perform - one for horizontal movement, one for jumping, one for attacking, one for wall jumping / sliding, one for grounded checks, etc...

Here is my scenario - In my Jumping MonoBehavior, when I press the Jump button I apply positive Y velocity to the RigidBody2D and I set the "isJumping" bool to true. My problem is that almost immediately after setting "isJumping" to true, it gets set back to false.

This is because in my Jumping MonoBehavior I have code that says If isGrounded = True then isJumping = false. Basically at the start of the jump my "grounded" raycasts are still colliding with the ground, the player hasn't achieved enough height between the jump being initiated and the next isGrounded check.

I need this "isJumping" state set properly as I use it to drive behavior for stuff like double / multi jumping, wall sliding / jumping, etc...

So I'm looking for advice on how to handle this. Is there some common practice / pattern that is used to handle this scenario? Or maybe I am going about this all wrong and there is some better way of handling jumping / grounded checks that completely avoids this scenario?

Any help / advice would be appreciated. I could post relevant parts of my code if that would help, I help off for the time being since this is more of an advice / approach question as opposed to a technical question. Thanks!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aksaini136 · Apr 30, 2021 at 05:22 AM

Hi @cjf420 , I am facing the same issue, did you find a fix for this?

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 sidslashy · Aug 07, 2021 at 06:22 PM

Hey! @cjf420 @aksaini136 I have a solution for that.

Try something like this.

  if (_rb.velocity.y == 0 && _isJumping && IsGrounded())
         {
             _jumpCount = 0;
             _isJumping = false;
         }

The issue is if you don't add the velocity check here, your ground detection might last an extra frame or two it takes to update the RigidBody position and reset your values prematurely.

Hope this solves your issue!

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 rage_co · Aug 08, 2021 at 02:45 AM

Physics.Raycast has a max distance limit...you can set it to an appropriate distance depending on where your raycasts start.... however, i am probably too late.....

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.

Follow this Question

Answers Answers and Comments

216 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

Related Questions

How can I fix this with my ground check? 1 Answer

My ground checker only works sometimes 0 Answers

Drawing a "rope" when the player jumps while not grounded 0 Answers

My player is flying up in the air when i start my game. 1 Answer

How do I disable Jumping while on my JumpPad? 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