Make object rotation perpendicularly to hit.point doesn't work properly.

Hello, I need your help !

I’ve created a script wich rotate an empty depending on the hit.normal

empty.transform.position = new Vector3(hit.point.x , hit.point.y , hit.point.z);

targetNormal = hit.point - Vector3.Cross(hit.normal, Vector3.right);

empty.transform.LookAt(targetNormal, hit.normal);

it works on almost every faces,
But when a face is oriented on the X axis (exactly) the empty doesn’t “rotate” on the normal and his rotation is the previous rotation of the previous face targeting

I guess I need to add a if statement but I’m pretty stuck here
Any help would be very helpfull !

thanks

hi,
I found the answer

if(hit.normal.x != 0)
        {
            targetNormal = hit.point - Vector3.Cross(hit.normal, Vector3.forward);
        }

        else
                {
            targetNormal = hit.point - Vector3.Cross(hit.normal, Vector3.right);
        }