How to perform intersection test between two colliders?

I have many enemy objects in a game that I am developing for iOS. I have found that colliders are using excessive processing capacity.

In many cases I only require collision checks between enemy and player. There is no need for enemies to be checked against anything other than the player.

So… I have replaced colliders with basic distance testing (in update script) and this has led to massive performance improvements. The problem is that the player is not spherical so collision detection of player is poor.

How can I manually test for intersection using either:

  • Two actual colliders (where one is disabled)
  • One actual collider and one sphere radius + position

Try using gameObject.renderer.bounds.Intersects

I have been using the following and it seems to be working for me:

public float collisionRadius = 1.1f;
private GameObject _player;

void Start() {
    _player = GameObject.FindGameObjectWithTag("Player");
}

void Update() {
    Vector3 playerPoint = _player.collider.ClosestPointOnBounds(transform.position);
    float playerRadius = Vector3.Distance(_player.transform.position, playerPoint);

    if (Vector3.Distance(transform.position, _player.transform.position) <= collisionRadius + playerRadius) {
        // Do something!
        GameObject.Destroy(gameObject);
    }
}