Calculating non-overlapping positions near a point

Hi all. I’m working on something of a strategy game, and i could do with some math assistance.

I’d like to select multiple units, and send them all towards a specified place. They should each take up a position somewhere near the specified place, without standing inside/ontop of each other.

I don’t have any need for formations here. Infact, i’d prefer it if the positions were sort of random and unorganised. But i’m worried if i just generate a bunch of random offsets, i’ll end up with overlapping sometimes as an inevitable result of probabilities.

I suppose i could bruteforce it by randoming and checking to see if the location is at least a certain distance from other locations, but that seems liable to be slow, and possibly lead to infinite loops.

I can assume that all the units will occupy a circular ground area with a certain radius. The radius may change from one operation to another, but all the units i’m moving in any particular group will have the same radius.

Can anyone provide thoughts on how to do this efficiently?

This might not be the best, or most efficient way to accomplish what you’re looking for, but here’s what I came up with.

You could create a grid where the specified target/position would be the origin, and create subdivisions (based on whatever radius you need) to represent available positions. Then you could just store the available position as integers in a list, and prevent multiple units moving towards the same position by removing elements from the list once allocated randomly to a unit.
Here’s a basic graphic in case my explanation sucked.

2365926--160640--Grid.png

hmm, it’s a bit too un-random is what i’m thinking, though. The outer nodes are unreasonably far from the centre point, so that they don’t really make sense. And if i restrict it to inner ones, it would still create a tight grid

How are you moving your agents? Sounds like close enough is good enough. Just set random offsets, then if the agents collide when they get close have them jostle and move one another.

I’ll probably use unity’s navmesh/pathing system.

I don’t feel like the inordinate amount of work required to make them move efficiently in formation, so i was planning to just not make them collide with each other. I suppose it could work though. collision and random offsets might just do it.

It’s not the solution i hoped for though, and it’s not a solution i’ll want to use later, this problem will definitely come up again. Right now i’m just knocking out a quick project but i was hoping to design a decent group placement function i can use more robustly, for a scenario where unit collisions aren’t enabled or relevant