I have an issue with my overlapCircle melee combat in the game. I'm not good at such things, so I just copied that code from some YouTube tutorial. But the thing is that if the enemy is behind the collider, I can still damage and kill him. And I don't want this. Is there a solution to this problem except recreating the melee combat system from the ground up? Maybe changing circle radius when close to collider?...

Here's a video clip that may help show the situation.

void Attack()
    Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, whatIsEnemy);
    foreach (Collider2D enemy in hitEnemies)
        Debug.Log("Melee hit: " + enemy.name);
        if (enemy is BoxCollider2D)
            CinemachineShake.Instance.ShakeCamera(3f, 0.2f);
            if (enemy.tag == "Melee enemy")
            else if (enemy.tag == "Gun enemy")
    animator.SetBool("IsCrouching", false);
    animator.SetBool("IsJumping", false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.