Hello, Im making a raycast with this code, its in the enemy to shoot the player:
void Update()
{
timer += Time.deltaTime;
shootRay.origin = transform.position;
shootRay.direction = transform.forward;
if (Physics.Raycast(shootRay, out shootHit, range, playerMask))
{
PlayerHealth playerHealthDetected = shootHit.collider.GetComponent<PlayerHealth>();
if (playerHealthDetected && timer >= timeBetweenBullets)
{
Shoot(playerHealthDetected);
}
}
}
My problem is that after, when i run the game, if theres a wall with a mesh collider between the player and the enemy, the enemy keeps shooting me. Why does this happend? The wall mesh collider doesn’t have a PlayerHealth component, is the raycast crossing that collider?
Thank you very much.