Hi,
I can’t find suitable way to find available space to fit circle object between others objects. Here is a screenshot to understand what do I mean
Googling doesn’t help at all, but it looks like quite obvious case I met in many games before.
Hi,
I can’t find suitable way to find available space to fit circle object between others objects. Here is a screenshot to understand what do I mean
Googling doesn’t help at all, but it looks like quite obvious case I met in many games before.
How are you doing the detection? I would just have an OnTriggerEnter2D and have 1 and 2 tagged as ‘correct’ and then all the other circles tagged as ‘incorrect’ you would then just need place circle colliders and match them up with the circle objects.
The exact same thing can be done in 3D, you would just be using sphere colliders and OnTriggerEnter, or are you thinking of something more complicated? If you want to get fancy, you can just change the material of the gameobject you’re moving as it is entering the incorrect colliders to red and so on, that’s really all there is to it.
There’s no way to immediately find a place in fixed time.
But there’s a good way to find spots like this.
Start by randomly distributing very small circles and gradually increase their size. When a circle collides with an obstacle you move it away until it doesn’t collide anymore.
When the center of two circles get very close, you remove one of them.
Once you can’t increase any more circles you’re done and all remaining circles are your result.
Oh hang on, yes, I totally misread what you wanted, you’re talking about having an algorithm procedurally place things! One minute, I may have an article I stumbled across when searching for this myself.
Thanks for reply, but that solution doesn’t work here. I assume it should be calculated by some mathematic formula using circles positions and diameters.
Exactly. Thanks, will be awaiting
Found it, knew it would be somewhere.
Wasn’t an article but a tutorial series, Quill18 did an entire series on this subject and it was about procedurally placing a galaxy, but given how simple the idea is that you’re trying perhaps you could apply the code here to your project. In this series he goes into a lot how to keep the instantiated objects a set distance from each other, there’s a lot there though, so you’ll need to do some learning.
Gave this a thought & worked out a way to do it.
First of all make your box smaller by the radius of your circle
Create a list of your circles with the radius of the circle you want to place added to theirs
Pick a circle randomly
Find any points of intersection around that circle where the other circles may now be overlapping
Pick a random spot on the circles radius that isnt in an intersecting part, if there are none redo above on a different circle
Cast a line out from that point away from the circle, the line will hit a wall or another circle
Pick a random spot on the line & spawn your new circle
Use Delaunay Triangulation. With the centers of the obstacles being the points of Delaunay graph. The centers of inscribed circles within the diagram will be the farthest points from all immeadiate surrounding obstacle centers.
Here is a link to the algorithm for calculating a Delaunay graph. the algorithm is clearly spelled out in easy to follow steps and its in O(nlogn) so should be super helpful.
once the graph is calculated, for each confirmed inscribed circle, check if its radius is greater than your placement circle’s radius + the largest connected obstacle’s radius. if not, that option can’t be used cause the placement can’t fit, otherwise its an option the placement circle can snap to.