Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 /
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. This is pretty important to me as I'm using this to stick the player to the ground. I've tried messing with the physics step but it hasn't done anything 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 jmhoubre · Sep 07, 2021 at 04:11 PM

Hello,

maybe try with OnCollisionEnter and OnCollisionExit, which 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 this there come some implications, one of which beeing: you do not get an exact result. floats bring inaccuracy and numeric iterations towards any solution bring some inaccuracy.

This is why in the physics settings there is a collision threshold which defines at which distance 2 objects count as colliding. This is not zero and should not be too small as this will only f up things. So depending on what you mean by "clearly" they have stopped colliding this might something that you cannot do that much about.


For anything further like options on what you could potentially do different to evade this 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 this 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.

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

why camera does not recognize the collision? 1 Answer

projectile must ignore collision with itself 3 Answers

Collider collision processing speed 2 Answers

One triggered event to take place between two trigger colliders? 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