OverlapSphere, Walls, Raycasting, Multiple enemies... issues.

void RocketExplosion()
{
foreach (Collider col in Physics.OverlapSphere(explosionPoint, areaRadius, collisionMask))
{
if (col.GetComponent() != null)
{
RaycastHit hit;
if (Physics.Raycast(explosionPoint, col.transform.position - explosionPoint, out hit))
{
if (hit.collider == col)
{
IDamageable damageableObject = hit.collider.GetComponent();
if (damageableObject != null)
{
damageableObject.TakeHit(damage, hit);
}
//col.GetComponent().AddExplosionForce(force, transform.position, radius, upwardsModifier, forceMode);
}
}
}
}

    }

I’m having a hard time with explosions using Overlap Sphere. As I understand it takes in all of the colliders in the sphere, then for explosions I’m trying to explode everything in that sphere, which seems pretty straight forward and that script handles that just fine. The problem is if you do this even on a collision mask it will kill every enemy that’s in the radius of it, which for most games probably wouldn’t matter. In a top-down-iso shooter or ARPG with a ton of enemies, it’s creating the issue since the collision was derived from OverlapSphere, there is no way that I understand to ignore walls unless you begin raycasting.

I’ve tried Raycasting after the explosion , but that leads to the issue that it only finds one point and stops. So it looks something like this. Here the bomb would hit the 8 red enemies and ignore the blue ones since the raycast cut off at the wall

Here though the bomb would only hit the first 4 objects around it because that’s where the raycast stops.
alt text

This also “blocks shots” in that if the enemies were lined up single file, I could hit the front one with a rocket/explosion and it would only kill the first enemy in total. Essentially I need a way to see if everything in the radius that will get hurt is

A) within range of the blast
B) not behind a wall

This seems simple enough, but after a couple days of head-desking I just can’t make it work and Raycasting doesn’t seem like my solution. Any suggestions/help is much appreciated.

public void CheckWallsForExplosion()
{

    foreach (Collider col in Physics.OverlapSphere(transform.position, scanRadius, lm_collisions))//make sure the enemy looks for the projectile
    {

        RaycastHit hit;
        if (Physics.Linecast(transform.position, col.transform.position, out hit, lm_walls))//linecast, NOT raycast as we need a linear result. mask set to walls only
            if (hit.collider.tag == "Wall")
            {

                isBehindWall = true;
                ChangeColor(); //do damage function or whatever you need to do at this point
}
    }

}

this issue was fixed by first scanning from the projectile with an overlap sphere , which told every enemy in range to execute the script above. However, there is still some super random stuff but for 99.9% of the situations out there it’s fine. If you are curious about the reasoning behind the fix or want to see what happened in more detail you can see this post:
https://answers.unity.com/questions/1446004/strange-and-questionable-behavior-with-overlapsphe.html