Aggro and unit collision


Just wanna start off by saying im fairly new to unity3d. I do how ever have a decent amount of experience with programming c#.

Im trying to make the basic skeleton for a RTS game and right now i have pathfinding and selecting units laid out, at the moment im also using rigidbody along with a Circle Collider 2D to make sure units can not stand on top of each other.

As i understand it, you can’t have two colliders of the same shape on a GameObject?

The problem here is that i need to have both Booth collision and and aggro between units trigger when they come in a certain range of eachother. Now im looking for the most efficient way of doing this as my game in the end hopefully should have 200+ units on the screen at the same time.

I could code collision by checking for units in the nearby sections of the map, and then do aggro range via the circle collider. But im not sure if this method is really that good as i dont know much about the collider :/.

So my question is pretty much, how would you do this most efficient?

Worth to know my game is in 2D.

You can’t have 2 of the same collides on a gameobject, but you can have children of that gameobject with their own colliders. If necessary, you can place them in different layers and then disable collision between certain layers. Or you can set colliders to be triggers only, so they don’t do rigid body collision but can be used as ‘sensors’. This actually works quite nicely as you can name the child objects to describe what they represent.

Whatever the exact scenario though, the basic solution is to have child objects with their own colliders configured to your needs.

And remember, you can always get back to their ‘owner’ through the ‘transform.parent’ member of the child’s gameobject.


You can’t have more than one of a component on an object. If you know that all of your units are circles, I would suggest doing the aggro check entirely in C# (for each other unit, squared distance check, etc). Literally doing a for-each might be too slow, but can make that much faster with some kind of spatial partition structure, even a simple 2D grid. If you don’t have such a thing already, it’ll help with other parts of RTS logic down the line.