• 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
Question by hamstar · Nov 04, 2013 at 02:25 PM · physicscollidercollisiondetection

Sphere collider catching edges of aligned cubes

My game allows users to create 2D levels with a tile based editor. In a level, a long platform is made up of multiple cubes. I have found that when a ball rolls over two aligned cubes (snapped precisely next to each other), the ball's collider sometimes catches an edge and bounces.

ball movement

I assume there is a collision detected at some time between gravity being applied and correction of the ball's height. Is that correct and is there any way around it?

To fix this I have tried:

  • The DontGoThroughThings script.

  • Using a mesh collider on the ball instead of a sphere collider.

  • Playing with the project PhysicsManager settings. Decreasing Min Penetration For Penalty and increasing Solver Iteration Count.

[edit]

I got a response from support. It sounds like the suggestions made here might be the only options. Here are quotes from emails (just relevant parts).

Their response:

"You can extend the collider to make a single object, thus eliminating the gap. Otherwise you can use two Quads to make the "floor" on which the sphere will travel."

My reply:

"I just tried using quads in place of cubes and I still had the same issue. Could you confirm if this should work? Extending the collider would not work for my current game design."

[edit2]

Tested more and found there is an improvement if I use a sphere Mesh Collider and convex quads for the floor (still catches but rarely). No improvement if I use a regular sphere collider with quad floor.

ball movement.png (47.5 kB)
Comment
Tomer-Barkan
Castermaluney
Johannski
petey
ajayyy
Hunter_Bobeck
Timmaeus
Raptosauru5
leohol

People who like this

9 Show 10
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 Tomer-Barkan · Nov 04, 2013 at 03:05 PM 0
Share

Did you try making the collider just a tiny bit larger than the cube itself, so they overlap?

avatar image drallim33 · Nov 04, 2013 at 04:44 PM 0
Share

I'm having similar problems, in all sorts of situations, always hitting corners on flat surfaces.

avatar image hamstar · Nov 04, 2013 at 04:58 PM 0
Share

@tbkn That sounds like it could work. I'll test it in the morning.

avatar image hamstar · Nov 05, 2013 at 09:48 AM 0
Share

@tbkn That didn't help unfortunately.

avatar image Tomer-Barkan · Nov 05, 2013 at 10:02 AM 0
Share

Too bad... are you sure they are overlapping? If they are, might be worth contacting unity support.

Show more comments

12 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by hamstar · Nov 07, 2013 at 09:26 PM

Thanks to everyone for the discussion and suggestions. Unity support got back to me with a fix. The solution was to set "Min Penetration For Penalty" to "0" in the project's physics settings. I tried reducing this value before, but wrongly assumed the value had to be greater than 0.

I can now use either box or quad colliders for the floor without problems.

Comment
Starwalker
Tomer-Barkan
Meater6
50p
Philon
petey
leohol

People who like this

7 Show 8 · 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 MikesNameIsMike · Mar 25, 2014 at 08:29 PM 1
Share

Do you know why this worked for you?

I'm very new to Unity and very frustrated at the moment. I have the same problem, and this does not fix it for me. I also see other people posting the same problem, most with no answer on how to fix it. It seems like Unity 2D physics isn't very polished yet?

Based on the description of the 'Min Penetration For Penalty' field here : http://docs.unity3d.com/Documentation/Components/class-PhysicsManager.html I don't really understand how this works. It sounds to me like a higher number should fix it, but I guess I'm reading it wrong. In either case, My circle collider is still occasionally jumping off the floor when I have two box colliders right next to each other under it. Was there anythign else you did to get this working?

avatar image hamstar · Mar 26, 2014 at 09:06 AM 0
Share

A higher number allows objects to overlap more without correcting their position (pushing them apart). Therefore, in my example, if I set 'Min Penetration For Penalty' to '0', the ball will never be inside the floor at all, it's position will be immediately corrected when they overlap. If I set a number large than 0, the ball would be allowed to overlap the floor a bit without correcting its position, and then may hit the left side of the second cube.

You can see this affect in my test project. To see this exaggerated, open Scene 2 and set Min Pen for Penalty to "0.1". After playing, set the value to 0 to see fixed.

Unfortunately the setting doesn't affect 2D physics. To minimise the affect you could increase the value of "Position Iterations" (make position update/correct quicker). Apart from that I don't know, you might need to ask Unity support.

avatar image PraetorBlue · Sep 30, 2015 at 04:09 AM 1
Share

As of Unity 5.2.0p1, this setting no longer exists!

http://docs.unity3d.com/ScriptReference/Physics-minPenetrationForPenalty.html

Anyone know how to fix this now?

avatar image hamstar PraetorBlue · Oct 03, 2015 at 06:32 PM 0
Share

PraetorBlue the page you linked mentioned new settings regarding "Contact Offset". Have you tried setting Physics.defaultContactOffset to 0?

avatar image PraetorBlue hamstar · Oct 03, 2015 at 06:40 PM 1
Share

That setting can only be >0

Show more comments
avatar image

Answer by MattusFinchus · Oct 19, 2015 at 12:27 PM

I had exactly the same issue but with moving a cube over a series of tiled cubes. Now and then it would just stop when it hit the edge of another cube. However, after much hair-pulling, I found that in the current version of Unity (5.2.1f1) within Edit > Project Settings > Physics, changing 'Default Contact Offset' from 0.02 to 0.001 did the trick. :) I must admit to being relatively new to Unity and am not sure if this will have any other consequences, but for the game I am working on, it seems fine. :)

Comment
qwiboo
Yilian3D
augivision
Timmaeus
leohol

People who like this

5 Show 3 · 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 qwiboo · Oct 21, 2015 at 02:07 AM 1
Share

This totally works in Unity 5! You just ended my 2 weeks misery! Thank you so much!

I was trying all sort of things (pretty much tried everything, merging colliders, different collider types etc.) and also changing the Default Contact Offset, but never tried making it smaller than 0.01 as I felt that's already small enough and you can't set it to 0. Well, I was wrong and setting it to 0.001 or something even smaller totally helped me get rid of unwanted bumps/jumps on the edges!

avatar image augivision · Apr 02, 2018 at 11:35 PM 1
Share

THIS HELPED ME QUICKLY! THANK YOU!!!

I had to set 'Default Contact Offset' to 0.0001 to get my game to work right.

THANKS AGAIN!

avatar image Hunter_Bobeck · Jan 03, 2019 at 09:08 PM 0
Share

It certainly doesn't help us out that to change it to a value that low, you have to type the number in; if you use the sliding feature by dragging the mouse it won't go that low.

avatar image

Answer by AlienFreak · Apr 07, 2016 at 06:53 AM

Edit->Project Settings->Physics Inspector will show PhysicsManager Set 'Default Contact Offset' from 0.01 to 0.001 (I use 0.0001)

This WILL fix it as I use a ton of cubes in a 3D cubic tile based world.

Comment
vbs
Hunter_Bobeck
Ondy

People who like this

3 Show 1 · 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 vbs · Sep 15, 2017 at 01:38 PM 0
Share

This is the change that worked for me as well, I use a capsule collider over a tiled flat surface of either box colliders or mesh colliders, although 0.001 worked fine for me, and my object can travel around 800+ km/h over the surface

avatar image

Answer by samifruit514 · Aug 26, 2016 at 04:47 AM

I'm having the exact same issue but the floors are made of BoxCollider2Ds. Setting the Fixed Timestep to 0.0005 instead of 0.02 seems to fix the problem, but it affects the performance overall :(

Unity team: Thanks for providing a fix for 3D, but do you have a good fix or a better workaround for 2D?

Comment
Robdon

People who like this

1 Show 1 · 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 Robdon · Nov 02, 2016 at 05:43 PM 0
Share

Thanks for the tip, that works for me!

I could get away with setting it to 0.005 though, so the performance hit doesnt seem to have hurt me much :)

Would be good though if the Unity team could 'fix' this for 2D, its a bit ridiculous that 2 flat colliders next to each other cause something like this. :(

avatar image

Answer by Hinkel · Sep 02, 2017 at 10:04 PM

Hey, I came across the same issue in my game. With the reduction of the "Default Contact Offset" my sphere (3d) isn't bouncing upwards anymore but the edges now seem to act as walls... if I collide with one of them my sphere just bounces back as if there was an invisible wall (doesn't happen at really low speed). I tried everything from playing around with the rest of the physics settings to combining my whole scene into one single mesh via Mesh.CombineMeshes and adding a mesh collider. I'm really frustrated since this is really necessary to work for my game. Did anyone of you finally found a fully working fix for this issue? Also is there a way to get around this issue with custom physics?

Sorry for my terrible English!

Comment
Raptosauru5

People who like this

1 Show 2 · 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 shough · Mar 17, 2018 at 02:55 AM 0
Share

Hinkel did you ever figure it out? I also have a reddit thread on this topic: https://www.reddit.com/r/Unity3D/comments/850wv2/ball_rolling_over_tiny_cracks_has_strange/

avatar image shough shough · Mar 18, 2018 at 07:53 AM 0
Share

I ended up using ProBuilder mesh welding works good. Occasionally crashes on very large mesh combines/subtracts.

  • 1
  • 2
  • 3
  • ›

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

39 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

Related Questions

HELP ME!! importing stuff!!! 2 Answers

Collider not stoping the object second time 1 Answer

Roller coaster colliding problems 0 Answers

Raycast and colliders problem. Corners of two colliders 0 Answers

How to find static objects in radius? Physics3D 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