Why do my projectiles hurt the player as soon as they're spawned?

I made a custom projectile, just something for an enemy to throw to try and kill the player, but it seems to hurt the player as soon as it spawns.

I got the code directly from the guide on here

void OnCollisionEnter(Collision collision)
{
Destroy(gameObject, 1);

var health = m_Character.GetComponent<Health>();

if (health != null)
{
health.Damage(Damage); // Inflict damage on the character.

}
}

But the projectile I made doesn't even touch the player before hurting them. Any idea why? Interestingly, my projectile still destroys itself 1 second after touching the enemy, so it clearly recognizes when its touching the player. The damage just happens way before it touches them.
 
It is most likely a matter of the colliders and layers. Make sure your player's colliders is not hit by your projectile or check the Impact Layers in your Shootable Weapon script.
 
I'm guessing the projectile is on a layer which can collide with the enemy, so as soon as it spawns, it collides with the enemy and starts Destroy (you've set 1 second as the timer there, so that'll be why it's delayed, not because it's waiting until it collides with the player). You need to either set up your collision matrix so that the projectile's layer doesn't collide with your enemy's layer, or you could put a check at the top of OnCollisionEnter.
 
It is most likely a matter of the colliders and layers. Make sure your player's colliders is not hit by your projectile or check the Impact Layers in your Shootable Weapon script.
I'm guessing the projectile is on a layer which can collide with the enemy, so as soon as it spawns, it collides with the enemy and starts Destroy (you've set 1 second as the timer there, so that'll be why it's delayed, not because it's waiting until it collides with the player). You need to either set up your collision matrix so that the projectile's layer doesn't collide with your enemy's layer, or you could put a check at the top of OnCollisionEnter.

Thank you both. I was able to fix my issue with one line of code made to check for my Character layer!
 
Top