Collider sometimes doesn't rotate when the rest of the object does

I’m making a turn-based strategy game with free-roaming movement (click to move rather than grid-based), and I’m trying to create a cover system. What I’ve got now is a Quad attached to each character which rotates towards the active player, then firing off a number of Linecasts to pick up see which ones can reach it. While this seems to work just fine at times, at other times it looks like the collider is at a different angle to the renderer. I haven’t been able to find anything in common with when it succeeds and when it fails. I’ve included the relevant code below and a couple of screenshots to show what’s happening when it works and when it fails. Any ideas?

Transform hitBox = _currentTarget.transform.Find("HitBox");

Vector3 lookPoint = _currentCharacter.transform.position;
lookPoint.y = hitBox.transform.position.y;
hitBox.transform.LookAt(lookPoint);

targetPoints.Clear();

Vector3 targetMin = hitBox.collider.bounds.min;
float targetXLimit = hitBox.collider.bounds.max.x - hitBox.collider.bounds.min.x;
float targetYLimit = hitBox.collider.bounds.max.y - hitBox.collider.bounds.min.y;
float targetZLimit = hitBox.collider.bounds.max.z - hitBox.collider.bounds.min.z;

for (int x = 0; x < 11; x++)
{
	for (int y = 0; y < 21; y++)
	{
		float targetXOffset = targetXLimit - (x * (targetXLimit / 10));
		float targetYOffset = targetYLimit - (y * (targetYLimit / 20));
		float targetZOffset = targetZLimit - (x * (targetZLimit / 10));

		Vector3 targetPoint = new Vector3(targetMin.x + targetXOffset, targetMin.y + targetYOffset, targetMin.z + targetZOffset);

		targetPoints.Add(targetPoint);
	}
}

47574-collider-problems-1.png
47575-collider-problems-2.png

Took me a while to figure this out, but it turns out that my problem was how I was calculating the x and z axis. As a result even though the hit box and collider were being rotated correctly, the calculations for hitting various points along it were always treating it as if it was pointing in the same direction. That worked fine so long as the targeted enemy didn’t have a greater/lesser x AND z position than the current character. For those cases I needed to run a slightly different calculation for the z coordinate to stop it. The actual code looks a tiny bit nicer than below, but it’s easier to demonstrate it when written as below.

    // Cover calculation - Quad hitbox
    Transform hitBox = _currentTarget.transform.Find("HitBox");

    Vector3 lookPoint = _currentCharacter.transform.position;
    lookPoint.y = hitBox.transform.position.y;
    hitBox.transform.LookAt(lookPoint);

    //_targetPoints.Clear();
    _targetScanPoints.Clear();

    Vector3 targetMin = hitBox.collider.bounds.min;
    float targetXLimit = hitBox.collider.bounds.max.x - hitBox.collider.bounds.min.x;
    float targetYLimit = hitBox.collider.bounds.max.y - hitBox.collider.bounds.min.y;
    float targetZLimit = hitBox.collider.bounds.max.z - hitBox.collider.bounds.min.z;

    bool xGreater = false;
    bool zGreater = false;

    if (_currentTarget.transform.position.x > _currentCharacter.transform.position.x)
    {
        xGreater = true;
    }

    if (_currentTarget.transform.position.z > _currentCharacter.transform.position.z)
    {
        zGreater = true;
    }

    for (int xz = 0; xz < 11; xz++)
    {
        for (int y = 0; y < 21; y++)
        {
            float targetXOffset = targetXLimit - (xz * (targetXLimit / 10));
            float targetYOffset = targetYLimit - (y * (targetYLimit / 20));
            float targetZOffset;

              if (xGreater == zGreater)
              {
                  targetZOffset = xz * (targetZLimit / 10);
              }
              else
              {
                  targetZOffset = targetZLimit - (xz * (targetZLimit / 10));
              }

            Vector3 targetPoint = new Vector3(targetMin.x + targetXOffset, targetMin.y + targetYOffset, targetMin.z + targetZOffset);

            _targetScanPoints.Add(new TargetScanPoint(targetPoint));
        }
    }