To get all enemies inside the explosion radius it works fine.
My problem is to apply damage to every enemy by distance, i’m doing it with this code:
var proximity : float = (transform.position - hitColliders*.transform.position).magnitude;*
it uses the position of the spell explosion and the enemy position but if the enemy collider is too big the center position gets too far from the explosion and the spell doesn’t apply the desire damage some times it even applies any damage at all. i attach an image that reflects the issue [28938-untitled-1.jpg|28938]*
*
For 2d colliders you might want to use Physics2D.Raycast. Since that might not give you the exact distance you could do 2 raycasts. One from your explosion center to the center of the enemy. From the hit information you can get the hit normal and do another raycast from your explosion center along the inverted normal. If you don’t hit the enemy, use the hit point of the first raycast. If it hits, use the new hit point as it should be closer.
Alternatively you might just attach a 3d BoxCollider as trigger and use ClosestPointOnBounds
I’m about to give up with this, if i raycast and an enemy is on the way, the one in the back don’t get any damage.
The answers that i found doesn’t work in 2D.
Any other idea? if not i will set the explosion damage to a fix percent.
I tried a lot, raycasting, CircleOverlap, CircleCollider2D , but nothing works…
so frustrating , just need to get the hit.point and calculate the distance.