✓ Accepted answer
To see if a models' parts are intersecting with anything, here's what you could do:
- Get all parts in the model, then call
:GetTouchingParts(). This will return a table with all the parts that are intersecting with that part.
- Loop through the table, and only check if there are parts that don't belong to your model. This eliminates parts inside other parts that are part of the model, since we're checking if the model is colliding with the environment.
- If there are parts in the table that are not descendants of your model, then yes, you're colliding with something. This is where you make your model turn red or something to indicate that you can't place there.
If you have a hitbox part for the model, though, you could just do step 2 only for the hitbox instead of every part.
Also, here's a bug to keep in mind:
:GetTouchingParts() doesn't really work as expected with walkthroughable (CanCollide = false) parts, it would just return an empty table each time. The solution to this is connect to the part's Touched event prior to calling :GetTouchingParts(), then disconnect from the event; this makes it return what parts are intersecting as expected. I learned this from here.
I recommend reading this SH guide by EgoMoose since that seems to be what you're going for. Don't get intimidated by the first part of the post though
Hope that helps!
2 comments
Mind sharing your attempt?
:GetTouchingParts()