Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I use MoveTo() on a model and have it CFrame into parts?

Asked by
Xduel 211 Moderation Voter
10 years ago

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

0
Just make the terrain flat... Or I suppose you could use a for loop and change the CFrame of each individual part. Perci1 4988 — 10y
0
Well that wasn't very helpful. Thanks for the consideration I guess. Xduel 211 — 10y

1 answer

Log in to vote
5
Answered by
2eggnog 981 Moderation Voter
10 years ago

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.

0
Thanks for the help, I also until now didn't know about GetModelCFrame or GetModelSize! Xduel 211 — 10y
Ad

Answer this question