I have a ball rolling across a floor consisting of multiple box colliders that are lined up.
However, when the ball crosses an intersection between two different colliders, it acts like it’s hitting a corner and bounces upwards.
(6 second video showing the issue)
How can this be solved?
Preferably without having to create one big floor collider, since the plan is to create multiple different pieces and dynamically place them at runtime
This is a long running 3D physics problem (I seem to recall @MelvMay implemented a solution for 2D). Boxes are your worst choice for this setup; as you can imagine, small precision deviations present the boxes as tilted or raised to one another, combine this with the contact offset and you start to get small edge trips.
I believe that some improvement can be had by reducing Collider.contactOffset to a “small” number (it is required to be positive, but you could make it near zero, say 0.0001 to 0.000001), this is all theoretical to me, I have no experience of it, so you will need to experiment with values.
Adding a little bounce to your physics materials may make them more forgiving of these errors when they arise.
I believe collision detection Continuous will be better than Speculative, so check that.
I think the best solution would be to combine the meshes, using: Unity - Scripting API: Mesh.CombineMeshes and then weld the duplicate vertices together (be sure to weld the ones with duplicate normals or recalculate a combined normal) this guy has posted his welding code, perhaps it can help you too Mesh Combine/Welding optimization for mobile I think combine leaves the children there, so you may need to disable them after you generate the combined mesh.
1 Like
Thank you, that’s a lot of good advice.
I’ve been experimenting with the contactOffset value but seems like there’s a risk of it happening regardless of the value.
Combining meshes seems like the most lucrative approach, I’ll look into that!
I saw that the Havok physics engine also has an option called “contact welding” that’s meant to tackle this issue, but I may go for the manual approach of welding meshes together.
Have had trouble getting Havok working at all. Despite installing the package and enabling it with the Physics Step script as explained here, Unity seems to still use Unity Physics and won’t swap to Havok.
1 Like
Sorry I don’t know about Havoc, I thought that was just for use in DOTS, but I may well be wrong.
Edit:
https://docs.unity3d.com/Packages/com.havok.physics@0.1/manual/faq.html
Item 1.
1 Like