Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by I-am-Lawrence · Mar 18, 2017 at 01:12 AM · rigidbody2djumpingisgrounded

Trouble detecting when Rigidbody2D character lands. (Not so simple)

Hello all,

I need help checking if my RigidBody2D character has landed from a jump. I can't seem to think of a way to get around these issues:

Must allow for PlatformEffector2D for one way platforming. This means we can't simply raycast below us or else when we jump through a platform from below, we will be considered 'landed' or 'grounded' in the middle of our jump.

Must allow for jumping onto slanted platforms. We also can't simply check to see if the y velocity is <= 0, because if we jump onto a slanted platform and continue running uphill, then our velocity never drops below or = 0.

Jumping right after landing must feel reactive. I mention this because I would just use OnCollisionEnter2D and check the impact point's normal, but OnCollisionEnter2D feels incredibly delayed, and seems like it's getting called late, which is kind of annoying.

I'm not really sure what other approaches I can take that don't get messy, so if anyone has any suggestions please let me know! I've been struggling with this for a while, and would like to move on.

Thanks everyone, Lawrence

Comment
Add comment · Show 2
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 Firedan1176 · Mar 18, 2017 at 03:50 AM 0
Share

For your first problem, you could just check to see if the platform has a PlatformEffector2D and wait until the velocity is

I'd recommend looking at Sebastian Lague's series here.

avatar image I-am-Lawrence · Mar 18, 2017 at 09:34 AM 0
Share

Thanks, I like watching Sebastian's tutorials, but the issue with his implementation is 1) He doesn't use a rigid body, which means no built in physics. All simulations would have to be custom built, and 2) he uses raycasts to detect collisions, so he would not be able to use the built in PlatformEffector2D for one way platforms.

Does anyone know if there is a way to mimic OnCollisionEnter2D without the frame delay? If I could do that then my problems would be solved.

1 Reply

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

Answer by I-am-Lawrence · Mar 18, 2017 at 10:51 AM

So I did find a way to detect when a rigidbody lands. I compared the angle of the Rigidbody's velocity to the angle of the ground below the player. If the velocity is perpendicular or tilted toward the negative normal, or there is no velocity, then we can assume the rigidbody has landed. I don't know if using raycasts in this manner will behave properly with PlatformEffector2D colliders, but so far so good...

So my formula looks something like this... hit is a downward raycast a short distance to the ground.

                 if (Rigidbody.velocity.sqrMagnitude == 0)
                     IsJumping = false;
                 else
                 {
                     float VelocityAngle = Vector2.Angle(-hit.normal, Rigidbody.velocity);

                     if (VelocityAngle <= 90)
                         IsJumping = false;
                 }
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

63 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

Related Questions

2D walls affect my jump height 1 Answer

Raycast2D Only returns true 1 Answer

Detect RigidBody2D Collision Only With Certain Velocity 0 Answers

player jumps too high when clicking with two fingers. 2 Answers

Simple Rigidbody2D movement and jump 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