How do you RaycastHit2D certain layers?

I’ve read the docs saying that that

int layerMask = 1 << 8;
layerMask = ~layerMask

will strike every layer but the player. I’m still only hitting the player though. I’m trating to raycast for walls, which are on layer 10. I’ve tried layerMask = 1 <<10, but that didn’t work. Maybe I’m sending in the wrong Vector2 for direction.

I’m testing with down arrow for now. Also tiles are 16x16, so quite small.

// Update is called once per frame
	void Update () {

		if (turn == true && !gameEngine.GetComponent<game_engine>().return_pause()) {

			// if character has turn, and game not frozen move

			if(Input.GetKeyDown(KeyCode.UpArrow) && north == true)
			{
			
					transform.position += new Vector3(0,1,0);

			}

			if(Input.GetKeyDown(KeyCode.RightArrow) && east == true)
			{
				
				transform.position += new Vector3(1,0,0);
				
			}

			if(Input.GetKeyDown(KeyCode.DownArrow) && south == true)
			{
				if(raycast_travel(new Vector2(0,-1)))
				{
					transform.position += new Vector3(0,-1,0);
				}
			}

			if(Input.GetKeyDown(KeyCode.LeftArrow) && west == true)
			{

				transform.position += new Vector3(-1,0,0);

			}

		}
	
	}
		// return false if raycast hit
	public bool raycast_travel(Vector2 travelDirection)
	{

		// create layer mask for objects
		int layerMask = 1 << 8;
		layerMask = ~layerMask;

		RaycastHit2D hit = Physics2D.Raycast(transform.position, travelDirection, 1.0f, layerMask);

		if (hit.collider != null) {

			Debug.Log ("RayCast: " + hit.collider.gameObject.tag);
				
			switch(hit.collider.gameObject.tag)
				{
					case "wall":
						return false;
					break;
					default:
						return true;
					break;

				}

		} else {

			return true;

		}

	}

Thanks for reading.

Your code seems ok at first glance, but it’s fragile (what is layer 8? And is that definitely the layer your player is on?)
Rather than rely on bitshifting and bitmasking operations, I recommend you use the builtin LayerMask helper functions, like GetMask, which will allow you to create a layermask from specified named layers:

int layerMask = ~(LayerMask.GetMask("Player"));

That will create a mask of every layer except the one named “Player”.