Prevent raycast from detecting certain objects

Hello, What I’m attempting is to make a raycast entirely ignore a certain layer. I’ve got this code here (so far)
The issue is this is doing the reverse of what I was looking for. it ignores ALL layers other then 8.

int layerMask = 1 << 8;

    public Camera FPScam;

    void Update () {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            Shoot();
        }
    }

    private void Shoot()
    {

        RaycastHit hit;
        if (Physics.Raycast(FPScam.transform.position, FPScam.transform.forward, out hit, range, layerMask))
        {
             //Do Things
        }
    }

I think what you want is:

 int layerMask = ~(1 << 8);

Alright, that worked! Thanks so much, I don’t normally use INTs like that so I had no clue lol

no problem. Ya… I can imagine. :slight_smile:
~ is binary ‘not’ (or one’s complement, so says wiki when i looked it up to be sure i was giving decent advice ;)). lol

also if you make the layermask public variable,
its easy to assign and combine layers with that layermask dropdown menu
3222303--247047--upload_2017-9-16_16-2-11.png

Ah good point / reminder :slight_smile: