Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Yiorgos · Nov 03, 2021 at 08:16 AM · collidercolliderscollision detection

OnCollisionEnter sensitivity

I'm creating a casual basketball game and I'm having a hard time configuring the colliders sensitivity.

More specifically: I put a mesh collider on the rim to detect if a swish (only net basket) is scored, but even when the ball seems to pass right through without touching anything, OnCollisionEnter triggers on the rim.

For example, in the screenshot, when the ball falls vertically the collider triggers. Is there a way to adjust the sensitivity so that it doesn't?

Top-Down view Physics Debug Visualization

screenshot.jpg (111.5 kB)
screenshot2.jpg (184.1 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by oscarAbraham · Nov 03, 2021 at 08:52 PM

There's no concept of sensitivity in this matter. Either an object entered a trigger or it didn't. It'd be easier to help you if you provided some images with the actual shape of mesh collider and its configuration in the inspector.

That said, I bet this is the root of your problem: I think you're using your mesh collider with Convex and Trigger turned on. Rings are concave shapes (i.e. non-convex). To make a mesh collider work as a trigger, you must have turned on the "convex" option. Convex meshes are those where a line can be drawn between every pair of vertices without going outside the mesh; so a mesh with a hole like yours doesn't fit the category, and its hole will be ignored.

Here are two possible solutions:

1. Use multiple box colliders make up the shape of the ring. You'll likely receive multiple trigger callbacks, one for each collider that was triggered, so your code will need to be able to ignore the extra calls.

2. Use a cylinder trigger that covers the complete basket hole. Then, in your trigger callback, measure the distance from the ball to the center of the cylinder: if the distance is small enough, the mesh wasn't touched. I'd prefer this solution because it's cleaner and allows you to easily add other functionality. For example, now you can change the distance-to-center threshold according to difficulty settings. You can also use the same collider to detect all kinds of stuff, like the speed of the ball, or if the ring is being touched.

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 Yiorgos · Nov 03, 2021 at 10:33 PM

Thanks for the detailed answer, Oscar.

Sadly, I've already tried adding box colliders around the rim and I had the same issue. By the way, I'm using OnCollisionEnter, not OnTriggerEnter, so my rim mesh collider isn't marked as convex/trigger. Moreover, when the ball falls directly in the middle, OnCollisionEnter is not triggered so the hole is not totally ignored.

Comment
Add comment · Show 4 · 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 oscarAbraham · Nov 04, 2021 at 07:14 AM 1
Share

Hm. It feels like you'd have a lot more control with a trigger instead of a solid collider. Anyway, then all you have to do is adjust the shape of the net collider to make it easier for the ball to pass through. This guide teaches you how to preview collider shapes to make things easier: https://docs.unity3d.com/Manual/PhysicsDebugVisualization.html

You shouldn't post this as an answer, though; this should be a comment under my answer.

avatar image Yiorgos oscarAbraham · Nov 04, 2021 at 08:52 AM 0
Share

You are right about the comment, my bad.

Thanks for the tip regarding the Physics Debug Visualization, I wasn't aware of it. Using it, I noticed my rigidbody was extruding from the ball gameObject when the ball was moving fast (I added a screenshot in the original question). After some trial and error, I concluded it's the Collision Detection option of the rigidbody that does the trick. I was using Continuous Dynamic in order to keep my ball from passing through the glass when shot at high speed, and this seems to have caused the issue I was having. Changing Collision Detection of the ball to Discreet, makes the rim collision work almost perfect. Thanks, you've been a great help :)

avatar image oscarAbraham Yiorgos · Nov 04, 2021 at 04:21 PM 0
Share

I'd advise against disabling Continuous Dynamic for fast moving objects. It does make fast moving objects less prone to collide, but not the way you want. This will make your ball skip colliders when they are thin enough or when it's moving fast enough.

Show more comments

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

175 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

Related Questions

Strange issue with collider 1 Answer

Why when i move the player object through the door the ontriggerenter/exit event are not fire ? 2 Answers

Reset a collider during runtime to lose previous Physics.IgnoreCollision() calls 1 Answer

How can I change animation with colliders? Using AR and Vuforia. 0 Answers

How to detect collision between 2 objects while checking are they the ones that need to collide? 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