Hey friends,
I have a raycast emanating from an enemy towards my player. The code calling the raycast is as follows and is called in the enemy’s script:
void FireZeMissile(){
Debug.Log("BOOM");
int layerMask = (1 << 10) | (1 << 12) | (1 << 23);
layerMask = ~layerMask;
RaycastHit hit;
Ray shootRay = new Ray(transform.position, player.transform.position - transform.position);
if (Physics.Raycast(shootRay, out hit, 1000f, layerMask, QueryTriggerInteraction.Collide)){
if (hit.transform.gameObject.tag == "Shield"){
player.gameObject.GetComponent<PlayerHandler>().shieldscript.TakeDamage(damage);
Debug.Log("Shield hit.");
}
Debug.Log(hit.transform.gameObject.name + ", layer: " + hit.transform.gameObject.layer;
Debug.DrawLine(shootRay.origin, hit.point, Color.red, 100f);
}
}
My “BOOM” debug message gets hit of course and the shield debug never gets hit. Incredibly, the last Debug.Log reads “FPSController, layer: 23”. How is this possible?? Didn’t I just tell it NOT to hit layer 23 when I set up my layermask? Why could this be happening?? Additionally, “FPSController” does NOT have a collider. It has a child that does but that child is layered as “Player” (layer 11).
Does anyone know what is happening here?