So I have a procedural town system, and I use MoveTo() to randomly place houses where they could be to form a town. Sometimes, however, terrain will get in the way, making the anchored house float in the air above the ground. So is there a way I can use the MoveTo() function to CFrame the house into the ground? or could I get the children of all the parts in the model and do something with them? All answers appreciated, Thank You. ~Xduel
Instead of using the MoveTo
method, use the TranslateBy
method. It doesn't check for collisions.
local model = Workspace.Model --The model you're moving local point = Vector3.new(100,0,100) --Where you want to move it to model:TranslateBy(point-model:GetModelCFrame().p) --Subtracting the two points gives us what we need to offset the model by.
In your case, this might make the house teleport into the ground. However, we can easily fix that by translating it up by half its height.
local model = Workspace.Model local point = Vector3.new(100,0,100) model:TranslateBy(point-model:GetModelCFrame().p + Vector3.new(0,model:GetModelSize().Y/2,0))
Note that because it does not check for collisions, you need the exact point on the ground, otherwise the model could be floating or sinking.