I have the following code. My player and certain objects are in PlayerAndEnemies. I have a tilemap2d (which is what I want the raycast to hit) but it does not collide with it. The tilemap 2d does have a tilemap collider and is in other layers (such as default, and others I created). Can anyone point me in the direction for why this would not collide?
Movement movement = player.GetComponent<Movement>();
RaycastHit2D hit;
int layerMask = LayerMask.GetMask("PlayerAndEnemies");
//layerMask = ~layerMask;
if (movement.directionFacing == 0)
{
hit = Physics2D.Raycast(player.transform.position, Vector2.down, 100f, layerMask);
} else if (movement.directionFacing == 1)
{
hit = Physics2D.Raycast(player.transform.position, Vector2.up, 100f, layerMask);
} else if (movement.directionFacing == 2)
{
hit = Physics2D.Raycast(player.transform.position, Vector2.left, 100f, layerMask);
} else // 3
{
hit = Physics2D.Raycast(player.transform.position, Vector2.right, 100f, layerMask);
}
//Debug.DrawRay(hit, Color.red);
//Check distance of raycast
print(hit.distance);
print(hit.collider);