Ok, I found an temporary solution that give me the red normal
IF I want to keep my SphereCast Test, I have to do a second Raycast for having this surface normal (C'mon Unity, why we haven't a hitInfo.surfaceNormal information ??)
//here my sphereCast in someFunction
RaycastHit hitInfo;
Vector3 position; //origin of the sphereCast
float radiusRayCast; //radius of the sphereCast
Vector3 dirCast; //direction of the SphereCast
float magnitudeCast; //magnitude of my sphereCast
int layerMask; //layerMask used for both SphereCast & Raycast
float rayCastMargin; //margin magnitude of the second raycast
if (Physics.SphereCast(position, radiusRayCast, dirCast, out hitInfo,
magnitudeCast, layerMask))
{
//here my second raycast Test
Vector3 surfaceNormal = GetSurfaceNormal(position,
radiusRayCast,
magnitudeCast,
radiusRayCast,
hitInfo.point,
rayCastMargin,
layerMask);
}
And here my static fonction, who calculate:
public static Vector3 GetCollisionCenterSphereCast(Vector3 castOrigin, Vector3 direction, float magnitude)
{
Vector3 collisionCenter = castOrigin + (direction * magnitude);
return (collisionCenter);
}
public static Vector3 CalculateRealNormal(Vector3 origin, Vector3 direction, float magnitude, float rayCastMargin, int layermask)
{
//Ray ray = new Ray(origin, direction);
RaycastHit hit;
if (Physics.Raycast(origin, direction, out hit, magnitude + rayCastMargin, layermask))
{
//Debug.Log("Did Hit");
return (hit.normal);
}
Debug.DrawRay(origin, direction.normalized * (magnitude + rayCastMargin));
Debug.LogWarning("we are not suppose to miss that one...");
return (Vector3.zero);
}
public static Vector3 SetSurfaceNormal(Vector3 castOrigin, Vector3 direction,
float magnitude, float radius, Vector3 hitPoint,
float rayCastMargin, int layerMask)
{
Vector3 centerCollision = GetCollisionCenterSphereCast(castOrigin, direction, magnitude);
Vector3 dirCenterToHit = hitPoint - castOrigin;
float sizeRay = dirCenterToHit.magnitude;
Vector3 surfaceNormal = CalculateRealNormal(centerCollision, dirCenterToHit, sizeRay, rayCastMargin, layerMask);
Debug.DrawRay(centerCollision, surfaceNormal, Color.black, 5f);
return (surfaceNormal);
}
As you see in this pictures below, black Ray are indeed the exacte normal of the surface, and the yellow Ray, the normal created by the SphereCast. It works !
Unfortunatly, it demand a second Raycast, and we can't have the perfect normal Intersection, but for now, it's good enought for me.