Answer the question
In order to leave comments, you need to log in
How can I prevent a clone of one asset from spawning in the root of another in Unity3d?
Making a game in Unity3d. The language is C#. The situation is exactly like this. There is an asteroid asset. It clones from above at a random point in the backstage area and falls down. After a certain period of time, a new clone of the same asteroid appears and also falls down, and everything works. But if you add one more asset, the clones of which also appear from above behind the scene at a random point after a period of time, then there is a high chance that one clone will spawn in another. What to do and how it can be prevented? Thanks in advance.
Answer the question
In order to leave comments, you need to log in
Falling objects most likely have colliders, right? Use Physics.CheckSphere , if there is already an object at a randomly selected point, then throw it away and select a new one. Do this in a loop until you find free space, or the number of iterations does not exceed some threshold, for example, one hundred loops. In most cases this will be sufficient.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question