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.

[17424-ball+movement.png|17424]

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.

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.

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.

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. :slight_smile:
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. :slight_smile:

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 :frowning:

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

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!

Collision detection issues for cases: (bodies = colliders)

  1. Bodies in close proximity to each other
  2. Bodies overlapping eachother but are slightly displaced on Y axis.
  3. Fast moving objects, getting stopped by thin Bodies may pass through it.

Probable solution:

Other than what is suggested in the comments above, if they all don’t work, you can do this.

  1. When you are in “2d editor” mode, make a new prefab which DOES NOT have a collider on it.
  2. Now once you are done with “editing” the scene, check if two boxes are in close proximity to each other, knowing that the length of 2 objects is always going to stay the same (constant) since its a prefab instance, you can check if two objects are aligned at the same height (y - axis), if true, ‘Add’ this to a List or Array of “closeObjects”.
  3. Once you have placed the all the objects you want, use some event to take in the total count of close proximity objects, add all their lengths (via iterator loop), and make a new “box collider” with the length as a summation of all the prefabs in this array.
  • You can also make a new array once you start creating a sequence of objects of the same type and use this array to sum-mate a sequence.

What you are doing above is making a new “Box collider” with the length equal to the total length of “prefab” instances placed in a straight line, or in the same height.

Now you will have just one big box collider for a set of smaller prefabs which is computationally less intensive in case you have 40+ objects or prefabs on which the ball might bounce. Collision check is done for target object (ball) vs all colliders in the scene. Which makes it CPU intensive for the solver, cause its a mathematical operation checking bound intersection every frame; meaning 40 x 60 frames / sec / dynamic object (ball).

Unfortunately I dont have the most ideal solution for your editor in my knowledge which is fail proof with what you want.

Hope it helps.

Ive tried everything you posted here guys. My player is still bouncing. Im using a circle collider on a player and box colliders on a square tiles.
1.) Ive changed the size of tiles colliders so they should overlap each other.
2.) Ive set ‘Default Contact Offset’ from 0.01 to 0.0001
3.) Ive set “Min Penetration For Penalty” to “0.0001”
4.) Ive experimented with collision continous/discrete

I’m having this issue in my mini golf game. The courses are made from pieces that are snapped together. When I hit the ball it moves and then hits the connecting edges of two pieces thus making the ball bounce when it shouldn’t be.

I’ve set Default Contact Offset to 0.00001 and it doesn’t help. My gravity is set to -50 but that doesn’t seem to affect the collisions between pieces.

Hello folks !

I just bumped on this issue last week and was missing an internet connection. I finally found the solution as mentionned by @AlienFreak :

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.

This is the only way to fix this on Unity 5.5.0f3. Also, setting the Default Contact Offset to 0.001 don’t work well, however setting it to 1e-05 works perfectly. Setting it to a lower value just don’t work (I tried 9.999999e-42 without success…).

I had a similar problem, for anyone who still needs help, my solution was to use box renderers with children quad colliders along the surfaces you want to collide with. even though the edges are flush and shouldn’t collide, they do. By excluding these surfaces, the object will never wrongly catch on them.

Freeze rotation worked for me.

While also looking for solution to this issue, I found this guy blogging about few interesting solutions. I recommend checking them out!

https://blog.dakwamine.fr/?p=1904

Method 6 sounds like a good (but probably difficult) solution, however I struggle finding much info about how to manipulate/rewrite physics in Unity

Method 8 sounds the best, but I am not sure if this would work on non-straight surfaces (e.g. ramps, slides, rails/roller-coasters).

I was trying to find some way to contact this person and ask him further, but I was unable to find a single way to reach him.