• 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 Joxev · Sep 07, 2021 at 03:05 PM · collisionbugs

OnCollisionStay is inaccurate

I've been using OnCollisionStay for ground checking but it seems to be detected collisions for a few frames after they have clearly stopped colliding. T$$anonymous$$s is pretty important to me as I'm using t$$anonymous$$s to stick the player to the ground. I've tried messing with the physics step but it hasn't done anyt$$anonymous$$ng so far.

Anyone have any ideas?

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 Jean-Michel_Houbre · Sep 07, 2021 at 04:11 PM

Hello,

maybe try with OnCollisionEnter and OnCollisionExit, w$$anonymous$$ch set an isGrounded boolean to True or False after testing that it was the player who made the collision.

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 Captain_Pineapple · Sep 07, 2021 at 04:17 PM

Hey there,

from my experience @jmhoubre 's suggestion wont help as OnCollisionStay will not yield different results than OnCollisionEnter and OnCollisionExit.


Problem is rather that the physics engine is based on a so called numeric solver based on floating point numbers. Along with t$$anonymous$$s there come some implications, one of w$$anonymous$$ch beeing: you do not get an exact result. floats bring inaccuracy and numeric iterations towards any solution bring some inaccuracy.

T$$anonymous$$s is why in the physics settings there is a collision threshold w$$anonymous$$ch defines at w$$anonymous$$ch distance 2 objects count as colliding. T$$anonymous$$s is not zero and should not be too small as t$$anonymous$$s will only f up t$$anonymous$$ngs. So depending on what you mean by "clearly" they have stopped colliding t$$anonymous$$s might somet$$anonymous$$ng that you cannot do that much about.


For anyt$$anonymous$$ng further like options on what you could potentially do different to evade t$$anonymous$$s issue would require a lot more information by you on what you actually do in detail.

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 Chimz · Sep 25, 2021 at 07:35 PM

I don't know if you've found your solution or not (since I'm 18 days late), but here's my answer nonetheless:

As you said the onTriggerStay has a delay (because an object needs to stay in it for a little time to be triggered) so let's just go with a Sphere Cast that will check the Enter and Exit states.

Cast a Sphere on the player feet (I used an Empty Object for position), and check with a Sphere/Circle Cast if the player is Grounded or not;

I'm gonna post my code here but it's for 2D and I'm too lazy to convert it. So if you're working on 3D you need to make a few small tweaks like turning Circle to Sphere and such.

 public Transform groundChecker; //Position where the circle/sphere will be made
     public float groundDist = 2.2f; //Distance amount
     public LayerMask layermask; //Active Layers - will ignore other layers
 
     bool grounded;
 
     // Update is called once per frame
     void FixedUpdate()
     {
         ///Casts a circle to act as Ground Check Trigger
         ///If it reaches the ground, then player is grounded
         if (Physics2D.CircleCast(groundChecker.position, 0.49f, Vector2.down, groundDist, layermask))
         {
             grounded = true;
         }
         else
         {
             grounded = false;
         }
     }

Hope t$$anonymous$$s helps

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

196 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

Related Questions

Object's pass through each other? 2 Answers

How do I fix this weird collision "bug"? 1 Answer

Detecting Trigger Collision for Mecanim Animator 0 Answers

making bullets disappear when they collide 3 Answers

Player won't stick to moving cube 2 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