Discrepancy between Sphere Collider Radius and Vector3.Distance


I’m working on a 2d game. The turrets have a sphere collider to detect enemies that wander into their attack range. I can watch the enemies entering the collider, and then do a distance check on them (to ensure they are still in range).

Debug.Log("TurretScript.Enemy Position " + target.transform.position);
Debug.Log("TurretScript.Turret Position " + transform.position);
Debug.Log("TurretScript.EnemyDistance: " + Vector3.Distance(turretPosition, target.transform.position));

The Sphere Collider’s radius is 10. I’ve checked this with a debug.log. The enemy enters, and the distance check occurs in update, and reports the distance at over 15. I’ve paused and checked both object’s positions, and they seem right (allowing for the fraction of time it takes to pause.) The turret gun is a child object, but its transform is being used. Not sure if this has anything to do with it.

I could understand a small discrepancy, but can’t explain why this is happening. Help appreciated! Thanks in advance.

Do you have any scaling? Either on your enemy or the player object? That changes the size of your colliders.

The distance measures from the pivots of the two transforms. So as Owen says, if the pivot of the enemy unit is in the center of the mesh with a collider with radius 5, distance == 15.