# Weird bounce on collision with perfectly aligned (generated) meshes for fast object

## Context:

I am working on a procedurally generated marble/ball track. For that, I generate the track-mesh based on direction and orientation of a bezier curve.
To enhance performance, I cut this mesh into smaller pieces which align perfectly as you can see in the wireframe pictures

## Problem

When the marble rolls over a point where two meshes touch, it happens that the marble jumps randomly up like there was a little step. You can see this in the following gif:

## Details

• The ball uses `CollisionDetectionMode.ContinuousDynamic` collision detection

• The track is a kinematic rigidbody with `CollisionDetectionMode.ContinuousSpeculative` collision detection. Usually, Just continuous collision should be used but since kinematic rigidbodies do not support that, I use speculative instead (see this document: Unity - Scripting API: Rigidbody.collisionDetectionMode)

• The ball has a physics material attached:
`dynamic friction = 1 static friction = 1 bounciness = 0 friction combine = maximum bounce combine = minimum`

• Note, that the ball rolls completely fine when using a single mesh.

• the movement of the ball is achieved entirely by controlling the angular velocity. The friction handles the rest

Does anyone have an idea why the ball jumps even if there is no reason to?

Best regards
Felix

Just a guess.
Collision detection works like this: when 2 colliders intersect each other by some value (default is 0.01) the collision is triggered and the physics engine starts to adjust the velocities of the objects.
While your marble rolls along the first mesh, it is always drown into the mesh for 0.01 units and constantly tries to fall down further but the engine pulls it back up. In this process, the velocity of the marble is kept aligned with the mesh surface plane (marble velocity + gravity + mesh surface counter force = approximately parallel to the mesh surface).
At some moment the marble touches the next mesh, intersects it for the same 0.01 units, and the engine detects that there is a new collision happened. And the place where it happens is the next mesh’s edge (probably 2 perpendicular planes: 1st is aligned with the previous mesh, 2nd goes down from the edge).
And if the marble velocity magnitude is high enough than it is treated as a hard crash into the edge of the new mesh, and the engine applies a big counter force impulse to the marble that consists off the up force from the horizontal plane and backwards force from the plane that is perpendicular to the upper surface, and when it is applied to the current velocity the velocity leans closer to Vector3.up.

This is a pretty well known glitch in most physics engines. Even when two things are perfectly aligned, there is occasionally a bump, but only at high speeds. For example, in a game called Trackmania, this is a well known glitch that the car bounces on the edges of track blocks where different blocks meet. You may just have to work around it. I think it might have something to do with precision errors in calculating high speed collisions.

I guess I’m kind of late here, but what did end up working for me was decreasing the default contact offset value (Edit → Project Settings → Physics → default contact offset) from 0.01 to 0.001, but the jumps still happen sometimes. I think you can set the value even lower, but the result at 0.001 was good enough for me (from 1 in 10 to 1 in 300)