Determining line of sight and partial cover

I’m making an overhead view turn based strategy game. When the player tells a unit to attack a target, the unit should check LOS to the target. However, I don’t want to just check the center point. I want to calculate a cover rating based on how much of the target (or rather, its collider) is visible. How can I get the “cross section” of the collider to send the raycasts to?

1 Answer

1

In the end, the player isn't going to notice how the "partial cover" is calculated, so you can sort of "fake" it, as I'm guessing it's not necessary to get an exact amount. You could simply trace rays to different parts of the target unit; for instance, trace a LOS to the head, torso, and legs and calculate the partial cover based on how many rays made their mark and how many hit something else.

But how do I calculate where to send the rays in a generalized way? Possible units could include anything from infantry to tanks, and I need to account for the unit being able to face any direction relative to its attacker. I can't just define a few points to always send rays to, because the points I need depend on the rotation of the collider.