rts on mobile : how can units find each other as simple as possible


I have a grid of 100 by 100 tiles.
each tile has a list of units that are currently standing ontop of it.
in this grid 500 units of team 1 and 500 units of team 2 are randomly walking around.
while they are walking around they place themselves in the unitlist of each tile they are on.
problem: Each unit has to check lets say a square of 6 by 6 tiles around the tile he is on, to check if there is an enemy nearby.

my solution. each unit checks on top of what tile he is and only when it changes tiles it will check the 36 tiles around its current tile and check all their unitlist to check for nearby enemies…


  1. isn’t there a better way to do this? Because when I need my units to have a bigger line of sight of lets say 15tiles it needs to check 1000units * 15tiles *15tiles = a gazillion…
  2. Does there exist a very inexpensive way of using somekind of a basic circle collider in unity without the need for rigid bodies etc…?

See if

will work for you.

I thought I would post my test for the Physics.OverlapSphere tip from getyour411 for those of you who wonder how to use this as an alternative solution for the problem with less units…

void checkForEnemiesWithSphere()
    		LayerMask layermask;
    		if(myTeamNr == 1){
    			layermask = 1 << LayerMask.NameToLayer ("UnitLayerTeam2");
    			layermask = 1 << LayerMask.NameToLayer ("UnitLayerTeam1");
    		Collider[] hitColliders = Physics.OverlapSphere(myCurrentPos, 5.0f, layermask );
    		for(int i = 0; i< hitColliders.Length ; i++)
    			if (hitColliders*.transform != this.transform)*
  •  	{* 

_ //Debug.Log(“I, (”+ this.name +") SEE YOU-> Name: " + hitColliders*.name);_
_ myLockedEnemy = hitColliders.transform.GetComponent();*_

* break;*
* }*

* }*
* }*