# How to represent two units on the same hex

I’m making a turn-based strategy style game, and I want a way to have two units on the same hex without them overlapping (or at least mostly not overlapping) each other.
The first issue is this: the way I calculate ranges assumes the unit is in the exact centre of the hex, so it will be messed up if there are for example two units in the hex which are slightly offset from the centre. I would assume using the actual hex that the unit is on to calculate range would be the best solution and I have an idea of how to go about it so this is not the main problem.
Assuming the above issue is solved, how could I go about separating the units when one enters a hex which already contains the unit. I want it so if there are two units they will be side by side, if there are three they will be in a triangle etc (unless you can suggest a better way).

1. The size of the units ranges from about 1/3 of a hex to almost the whole hex.
2. They can overlap a little bit as long as they are clearly distinguishable
3. They can spill onto other hexes as long as the centre is on the actual hex it is on.
4. I am not using a hex grid. The hexes are 3d objects.
5. I am moving the units by lerping transform.position with the end position at the hex’s x and z coordinates.
6. I am not currently keeping track of which units are on a hex, but I am keeping track of which hex each unit is on by doing a spherecast from a point directly below the unit and inside its hex.
7. I imagine I will have to eventually keep track of which units are on a hex, so I will probably do that by for each hex looping through all the units (there aren’t many, usually <20) and checking if the hex the unit is on is the current hex, and if it is, adding the unit to the list of units on that hex.

Vector3 centerOfHex;
Transform unitsToPlace;
//how far each unit will be from the center of the hex
float distanceFromCenter;
if(unitsToPlace.Length == 1) {
//if there is one unit, just place it on the center of the hex.
unitsToPlace.position = centerOfHex;
} else {
//otherwise:
//find the desired angle between units
float angleBetweenUnits = 360f / unitsToPlace.Length;

``````    //loop through every unit
for(int i = 0; i < unitsToPlace.Length; i++) {
//calculate the rotation around the Y axis (up) - In a 2d game you would want the Z axis instead (or Vector3.forward)
Quaternion unitRotation = Quaternion.AngleAxis(angleBetweenUnits * i, Vector3.up);
//get the position from the center in the calculated direction - Vector3.right will be the position of the first unit,
Vector3 unitOffset = unitRotation * Vector3.right * distanceFromCenter;
//place the unit relative to the center of the hex:
unitsToPlace*.position = centerOfHex + unitOffset;*
``````

}
}