Hello there! I seem to have run into a snag! I have a capsule collider at the feet of my player so that they don’t run through objects, and a boxcollider2D with “Set Trigger” enabled to work as a hitbox.
The problem is this: the projectiles will hit the player and trigger the TakeDamage() Function, but only if they hit the capsule collider at the feet of the player.
How do I address the projectiles passing through the boxcollider2D is trigger component?
I’m guessing this stems from the code snippet:
private void OnTriggerEnter2D(Collider2D other)
{
EnemyHealth enemyHealth = other.gameObject.GetComponent<EnemyHealth>();
Indestructible indestructible = other.gameObject.GetComponent<Indestructible>();
PlayerHealth player = other.gameObject.GetComponent<PlayerHealth>();
if (!other.isTrigger && (enemyHealth || indestructible || player))
{
if (player && isEnemyProjectile)
{
player.TakeDamage(1, transform);
}
Instantiate(particleOnHitPrefabVFX, transform.position, transform.rotation);
Destroy(gameObject);
}
}
That pesky little part:
!other.isTrigger
Appears to be the source of the problem, but if this isn’t included, projectiles will hit tree transparency detection colliders and the canopy layer.