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

Why does :MoveTo() move my model to above the desired position?

Asked by 5 years ago

When I use :MoveTo() on a model, it's moved to a position but above the desired position.

I'm trying to move a model of around 10 parts to a position of another part in workspace, but it's not moving directly to the position of that part, but above it or on top of it. What's the solution?

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

MoveTo() does a "safe move" where it will not allow the model being moved to overlap with collidable things at the destination. It will move parts upwards until nothing is colliding. If you want to move the model without collisions being considered, what you do is make sure your model has a PrimaryPart set (the part in the model that represents its position), and then do

model:SetPrimaryPartCFrame( targetPart.CFrame )

Note that this will align the model's primary part with the target part, including orientation! If you only want to align position, (preserve the model's current orientation), you can do this:

local cf = model:GetPrimaryPartCFrame()
model:SetPrimaryPartCFrame( (cf-cf.p) + targetPart.Position  )
0
That's the answer I was looking for, thank you so much Emily :) excellentAnarchy 50 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Maybe the other/ the model you're moving is un-anchored? It's physically impossible to put a block inside another using script when they're both/one of them is un-anchored, if they're not welded together or something.

If you'd provide a script, then that would be good.

Another solution might be, if the one above wasn't the case,

So you want to move all the parts in the model to a position at once, right? So you can also, by the information you have given, could do(EXAMPLE):

--Let's say you have a model named EXS and it has 7 parts in it. You also have a part called EXY and it's one part in the workspace that you want to move the parts to.
local e = workspace.EXS -- Variables always first. They're lifesavers.
local lol = e:GetChildren() -- Gather the children parts or stuff.
local e2 = workspace.EXY
for i,v in pairs(lol) do -- Call those parts to wake up and do something.
    if v:IsA("Part") then -- Security check! No secret spies allowed. You need to be a Part to enter.
    v.Position = e2.Position -- Teleport those parts all at once to move to that part.
    end
end

Answer this question