RaycastHit2D not detecting hit on tagged object

Hi all!

Been having a bit of an issue with getting my raycast to detect when it is hitting a tagged object. All other searches seemed useful but no solutions I’ve found have seemed to work yet.
The rays constantly hit (even when not touching anything) when I don’t specify a tag but as soon as I do they seem to never hit at all.
Here is the code I am using:

	Debug.DrawRay (transform.position, Vector2.right, Color.green, 0f, false);
	Debug.DrawRay (transform.position, -Vector2.right, Color.red, 0f, false);
	
	RaycastHit2D rightHit = Physics2D.Raycast (transform.position, Vector2.right);
	RaycastHit2D leftHit = Physics2D.Raycast (transform.position, -Vector2.right);
	
	if (rightHit.transform.tag == "Wall")
	{
		rightWallHit = true;
		Debug.Log ("RightHit");
	}else{
		rightWallHit = false;
	}
		
	if (leftHit.transform.tag == "Wall")
	{
		leftWallHit = true;
		Debug.Log ("LeftHit");
	}else{
		leftWallHit = false;
	}

I’ve triple checked that the walls are tagged correctly and have even tried changing the transform to collider and rigidbody. I’ve also got one wall as rigidbody kinematic and one without a rigidbody just to be sure it’s not that. I’m all out of ideas and any help would be greatly appreciated!

Problem solved, be sure to check your layers everybody!