I am making a script that spawns tree models on a platform - the objective is for the script to spawn as many trees (in random positions) without the trees intersecting any other trees. For the spawning, I used cframes and :SetPrimaryPartCFrame() - (I used :MoveTo before, but I had trouble with that shifting the trees upward.)
Currently, the script spawns fine, but I'm not sure how'd I'd check if any of the other trees would be intersecting. And you'd think that "oh, use a touched event" or something. The problem is I don't want to put the tree model in the workspace until I know it won't intersect any other trees. The touched event probably requires the tree to be in the workspace.
I can't have a tree in the game temporarily because I have another script that detects trees as soon as added and does things with them - if the tree is temporarily there (even for 0.1 second) and gets instantly deleted, my script may try to use that tree.
Yes, I know there are many easy ways to go around this, but most of them are really messy.
I have a part with all the other trees inside of it. I'm trying to make it so, before inserting the tree into the game, the script checks if it would intersect any other trees.
I was thinking maybe a for loop and some heavy math conditions could cut it, but that would also be pretty big. Are there any easier ways to detect whether an object would be intersecting another?

3 comments
There are lots of options, depending on what you consider "intersecting". If your trees have a reasonably circular footprint, and it's acceptable for them to be no nearer to each other than you'd get from circle packing, the check comes down to just simple radius checks against the would-be neighbors.
If you want collision geometry level of precision, temporarily placing an invisible tree is by far the easiest solution.
Yeah I am not reading all that. Easy fix, use GetTouchingParts in an event.