- Home /
How to place an object near N number of objects in order to avoid overlap?
My users are set inside a sphere and I get a position from ray.hit in the surface of the spehre. Then I place an indicator, but sometimes they overlapp, weather the user do so or when I randomly place them.
How can I determine the ideal position near or among a given N number of indicators?
Hey there,
can you provide a bit more info on the problem? Perhaps a part of the code that you use?
i especially do not undestand what you want to say with "Then I place an indicator, but sometimes they overlapp, weather the user do so or when I randomly place them."
What is the goal? To place Indicators/markers on a sphere that do never touch? Please specify this for us.
Hey Capitan, my problem is related to this question, but cant implement anything they recomend in my case: https://answers.unity.com/questions/1486937/math-place-object-without-overlap-others.html
The users place an indicator, a sprite, in the inside surface of a sphere. For doing that I ray cast from outside the sphere and then correct the position. I dont have code for that yet. I just wanted to know if there is a way to pack circles without overlaping them.
Hm okay i think i understand what you are trying to do. Though unfortunatly that is quite difficult to do...
Could you perhaps save a vector for each marker that gives you the direction from the spheres center to each marker. Then you can at least check if a markers position is valid by comparing the vectors against each other. So when placing a new marker the angle between the vectors pointing to the markers from the spheres center has to be larger than 2*arctan(markerRadius/sphereradius).
Note though that this calculation is not completly exact since it it designed for markers on a flat surface. So given that your sphere is large enough compared to the markers you are trying to set on it this should give you are pretty good approximation.
Hope this helps
Umm, it's hard to understand what you want to achieve even with the link you provided. Can you explain the gameplay from player's viewpoint?
my solution would be to provide predefined slots the user can place stuff on. that's because all the automatic correction you're doing after a couple of them are placed won't let the user place them where he wants them anyway, so you could just go with that.