There is one easier way to do this and another more complicated way. If you want to make it so models can overlap as long as no parts touch each other or have shapes more complex than boxes then you are going to need to set up your own bounds around the object to compare other object's bounds to. If you are doing something with uniform square or rectangular shapes, then it is much easier.
There are two nifty function of every model, one called GetExtentsSize which gives you the bounds of that model and the other called GetModelCFrame which gives you the CFrame of the model. However you should set the PrimaryPart of the model as the bounding box is retaliative to the rotation of the PrimaryPart. Here is how you would check if they collide.
01 | local Model 1 = game.Workspace.Model 1 |
02 | local Model 2 = game.Workspace.Model 2 |
04 | function checkForCollision(model 1 , model 2 ) |
05 | local collided = false |
06 | local x, y, z = false , false , false |
07 | if (model 1 :GetModelCFrame().p.X < model 2 :GetModelCFrame().p.X + model 2 :GetExtentsSize().X and model 1 :GetModelCFrame().p.X + model 1 :GetExtentsSize().X > model 2 :GetModelCFrame().p.X) or (model 1 :GetModelCFrame().p.X > model 2 :GetModelCFrame().p.X + model 2 :GetExtentsSize().X and model 1 :GetModelCFrame().p.X + model 1 :GetExtentsSize().X < model 2 :GetModelCFrame().p.X) then |
11 | if (model 1 :GetModelCFrame().p.Y < model 2 :GetModelCFrame().p.Y + model 2 :GetExtentsSize().Y and model 1 :GetModelCFrame().p.Y + model 1 :GetExtentsSize().Y > model 2 :GetModelCFrame().p.Y) or (model 1 :GetModelCFrame().p.Y > model 2 :GetModelCFrame().p.Y + model 2 :GetExtentsSize().Y and model 1 :GetModelCFrame().p.Y + model 1 :GetExtentsSize().Y < model 2 :GetModelCFrame().p.Y) then |
15 | if (model 1 :GetModelCFrame().p.Z < model 2 :GetModelCFrame().p.Z + model 2 :GetExtentsSize().Z and model 1 :GetModelCFrame().p.Z + model 1 :GetExtentsSize().Z > model 2 :GetModelCFrame().p.Z) or (model 1 :GetModelCFrame().p.Z < model 2 :GetModelCFrame().p.Z + model 2 :GetExtentsSize().Z and model 1 :GetModelCFrame().p.Z + model 1 :GetExtentsSize().Z > model 2 :GetModelCFrame().p.Z) then |
25 | checkForCollision(Model 1 , Model 2 ) |
Now every time the model is moved you can call this function to determine if it should be able to be placed there or not.
NOTE This provided algorithm only works on models parallel/perpendicular to the world axis