Raycast Ignores all layers instead of specified layer
Its certainly the raycast because when I remove the Layer Mask. the problem is fixed…
Layer 8 is to be ignored.
public RaycastHit2D hitInfo;
public float reachDistence = 3.5f;
private Vector2 movingDirection;
int playerLayer = 1 << 4;
void Update () {
if (Input.anyKey)
{
movingDirection = new Vector2 (Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
Debug.DrawRay(transform.position, movingDirection, Color.red);
hitInfo = Physics2D.Raycast(transform.position, movingDirection, reachDistence, playerLayer);
if (hitInfo) //If raycast has hit a object
{
Debug.Log("Physical Hit!");
Debug.Log(hitInfo.collider.name);
}
}
}