- Home /
How can I duplicate an object and place it randomly near the original ?
Basically, I know how to duplicate the original object with Instantite(original.getClass) The tricky part is to know where to place it in the scene since I don't know what is the object being duplicated and I want it to be placed where it won't collide with other objects in the scene.
you could use the Physics to test if the desired spawn position is free of colliders
If the object does not exist yet, how to I use physics ?
from where you want to instantiate the object, lets say, you want to instantiate a Sphere, or atlest, check if the space available for a sphere has no other collider(or part of it) inside, you use Physics.CheckSphere(position, radius), returns true if there is a collider inside that "Ghost Sphere" or "Sphere to be instantiated", or use Physics.SphereCast(..., out hit) to get the hit as you would on an actual collider
Your answer
Follow this Question
Related Questions
Placing Prefabs in Prefabs. 9 Answers
clone object make a new script 0 Answers
Can I duplicate folder with internal dependencies between objects? 4 Answers