- Home /
Other
Instantiate an object at hit position without it intersecting anything
Hello! I am trying to make a building placement system, I have everything done except for positioning. I cannot seem to find a good formula to place an object on another object WITHOUT them intersecting each other. I am raycasting from the mouse position, So i have access to hit.point and other properties of a raycasthit
Any help is appreciated!
Answer by Dragate · Oct 10, 2017 at 09:02 AM
Since you know hit.point you could do a Physics.CheckSphere() at that position with the radius of the object you want to instantiate there. If it returns true, you Checksphere a bit higher until it returns false. At that point, you can safely instantiate your object.
Follow this Question
Related Questions
Raycast goes throught objects [C#] 1 Answer
Raycast function doesn't work. 1 Answer
[C# / Unity] Raycast Ignoring Self / Offsetting Instantiations? 0 Answers
[C#] UNET Client raycast not the same as Server raycast 2 Answers
How do I single out GameObject being detected by Raycast in a destroy / respawn system 1 Answer