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?
I can think of an easy way using the touch event. Before adding the tree and using a touch event to detect touching, make it transparent, or you could have a bool value inside it named "Testing" and set it to true. When the other script is messing with trees, have it first check whether the tree is transparent or the value of "Testing", whichever you do, and use that value to decide whether or not it should mess with the tree. If you have any questions, just comment.