I’m working on a tower defense game and rather than limiting the player to only placing towers on specific, predefined spots, I want to let him place them anywhere on the ground that is open. However, towers should not intersect each other or other world objects such as buildings or walls.
I’m wondering what the best way to implement this would be. I have a script on my camera that does a ray cast every frame to get the point on the terrain under the cursor, that’s simple enough. Now I want to know if the selected tower type will fit there, or if there is another obstacle nearby.
Should I attach a script to the tower that’s being placed on the ground, and in that script have an OnCollisionEnter() callback that simply tells the camera that the tower has collided with something and can’t be placed there? Or is there a way I can do a “cube cast”, kind of like how I can do a Physics.Raycast or Physics.SphereCast and handle the collision detection in the same script on the camera that I check for the ground point under the cursor?