Is there a way to intercept a collision before the Physics engine see it?

I have found a bug in Unity’s Physics engine and I need a work around badly. I am creating an open world game that is Voxel based. I have my terrain made up of several meshes that align up next to each other. Part of the game involves shooting a spheres with a rigid body attached, and it comes in handy to bounce them off the terrain. The problem is if the sphere hits the seem between two meshes the physics engine does not see this as a flat surface, and will treat the collision like if you were bouncing the sphere off the side edge of a cube.

I have tracked the issue down inside of OnCollisionEnter (see code below), but from what I have read I believe it is too late at that point to do anything about it as the Physics engine appears to already set things in motion.

I could not figure out how to post a Issue so I am posting here in hopes someone knows a work around. I waited for Unity5 to come out first to see if it was fixed, but no joy.

Ideally it would be nice if Unity fixed the bug, but I could not figure out how to post a new Issue in the Issue Tracker, and I could not find anyone else with this issue. It does appear to
be unique to the game I am creating as I do not use the Terrain system.

The closest thing I could find was this in the Feedback forum, and I gave them my votes:

http://feedback.unity3d.com/suggestions/function-for-manually-simulating

I have tried many things to fix this, including changing the settings in the Physics Manager. I was able to improve the situation a bit, but not fix it. Here is the code example that shows were
you can detect the issue, but I am stumped how to fix it:

void OnCollisionEnter(Collision collision) 
    {
        bool invalidNorml = false;
        int count = 0;
        for (int i=0;i< collision.contacts.Length;i++)
        {
            ContactPoint contact = collision.contacts*;*

if (contact.otherCollider.name.StartsWith(“blk”) )
{
count++;
if (Mathf.Abs(contact.normal.x) > .001f || Mathf.Abs(contact.normal.z) > .001f)
{
// the test surface has a normal of 0,1,0 but the physics does not treat the seem
// as a flat surface and returns some calculated normal
invalidNorml = true; // The test surface has a normal of 0,1,0
}
}
}
if (invalidNorml && count > 1)
{
// If the count of hits is only 1 then we are at an edge and not a seem.
// If we get more than one hit then this seems to be were I get the unexpected
// bounce in various directions, and even some cases the sphere will get stuck
// in the mesh if I happen to be at the intersection of 4 meshes
Debug.Log( “This is where I get the problem”);
// The problem is I think this is to late to do anything about it
// It would be nice if I could override the contact.normal here, and then let the physics engine
// take over after this method
}
}

Edit: @jrhtcg, have you tried using FixedUpdate? That’s were you need to perform calculations before the physics update.

I don’t know of any solution that comes before the physics check during the same frame. Here are some possible hacks -

  1. Raycast a short distance ahead on every frame, in order to predict whether there will be a collision in the next frame.
  2. slightly enlarge the collider of the mesh, so instead of a seam you’ll have a flat surface.
  3. combine the meshes and wrap them in a single mesh collider.

i don’t know much about unity physics engine. am just thinking you need collision before it collide . instead of collision enter you can try this Unity - Scripting API: Physics.OverlapSphere