# Collision normal for sphere near edge of triangle face

When my sphere (or bottom part of a capsule) moves with its bottom near the edge of a mostly horizontal triangle (a face of a heightmap), I am sometimes getting very bad (mostly horizontal) normals. How should a proper collision normal be calculated in this situation?

Here's my attempt to explain the current situation leading to these bad normals. Running the usual separating axis tests, it is determined that the best axis is mostly vertical. Based on this axis, the colliding features of the shapes are determined. The feature of the sphere is always a point on the bottom, and the feature of the triangle can be the whole face, an edge or a point. The bad normals here are arising from point-edge collisions. Namely, the best axis was determined to be mostly vertical, but it can happen that the point is extremely close to the edge, and vertically closer than horizontally (and so apparently a separating axis in the plane of the triangle was not considered or not the best), so that the contact pair consisting of the point of the sphere and the closest point on the edge has a normal which is mostly horizontal.

How should this problem be solved?

For reference: this is Godot issue #69683 which I would like to fix.

• I found this article Contact generation for meshes v1.2 by Pierre Terdiman, exactly about how to avoid this issue. Also it would be good to check what PhysX 5 is doing in this situation. Commented Dec 14, 2022 at 17:54