Raycast always hitting default layer

I have my raycast ignoring the layer its casting from and its showing that its hitting layer default now. which is layer 0.
Do I need to ignore default layer too? If so how do I ignore more then one layer.

            int layerMask = 1 << LayerMask.NameToLayer(characterSettings.Faction);
            layerMask = ~layerMask;
if(Physics.Raycast(FirePoint.position, FirePoint.forward,  out hit, AIDetectionSetting,layerMask)){

                Debug.Log(hit.collider.gameObject.layer);
}

This is a picture showing the ray cast.
Unless my ray cast debug isn’t showing the right ray cast

Debug.DrawRay(FirePoint.position, m_AIAgent.SharedMethod_TargetLookDirectionLookPoint(FirePoint.position, true) * 100, Color.red);


        public Vector3 SharedMethod_TargetLookDirectionLookPoint(Vector3 lookPoint, bool raycastLookDistance)
        {
            // If the transform is null then return the forward direction.
            if (m_TargetTransform == null) {
                return m_Transform.forward;
            }

            return (m_TargetTransform.position - lookPoint).normalized;
        }

int layerMask = 1 << LayerMask.NameToLayer(characterSettings.Faction)
This make a mask for only characterSettings.Faction
layerMask = ~layerMask;
this inverts it to NOT characterSettings.Faction

you are casting to all layers except characterSettings.Faction

Another tip too is I believe that if you expose the layer mask variable to the property inspector (I mean make it a public variable, for instance), you can actually check off the specific layers right in the property inspector, which is a little more friendly a way of going about it for the average person than bit shifting.

I figured out whats wrong. I assumed my raycast was the same raycast as the controller i was using. It wasn’t It was way off.
Thanks for that tip on the public variable. Thats pretty nice.

Thanks for the reply hpjohn
Ya Im wanting to cast to all except that layer.

Ah sorry, I misread the post
If you want to create multiple layer masks in code, use the bitwise OR operator “|
mask = (1<<x) | (1<<y) = mask for x or y
mask =~ mask = mask thats not x or y