MoveTo() is extremely inaccurate

I have a model that I want to move to a certain coordinate. in Workspace, I moved the model to the correct position, but in the game, the model is wayy too high and the pivot is set way below the model. I don’t know how to fix this and it seems that every time I change the script to make the model go more down, the pivot changes again. There are no errors in the output. How do I fix this??

local tower = game.ReplicatedStorage.ParkourTower:Clone()
tower.Parent = game.Workspace
tower:MoveTo(Vector3.new(x, -17.5, z))

(x and z are number variables)

1 Like

Update:
This is quite consistent but still unexplainable… Replacing -17.5 with -24.01 makes it about 2 studs away from where it’s supposed to be. Replacing it with -22.01 makes it at least 50 studs higher than it’s supposed to be. It doesn’t make sense!

1 Like

MoveTo is accurate for its purpose. It is intended to move a model to a given position, while adjusting the height such that the model is not colliding with anything else at the position. This is why the model is moved up.

If you don’t want this behaviour, consider using the newish function :PivotTo(). It behaves very similarly, except it doesn’t automatically move the model up

3 Likes

When I use PivotTo on a certain model, one of the parts rotates on its side for some reason

Use it in combination with :GetPivot() to get its original one. Then you can subtract its initial position and add its final position to get the final pivot for it

Use linear interpolation, lerp is good to do that, make for loop from 0-1 and step of 1/100 and then lerp by number:

local Tower = workspace.Tower

local start = Tower.Position
local finish = workspace.Finish.Position

local function Lerp(a,b,t)
return a+(b-a)*t
end


for i = 0,1,0.01 do
Tower.Position = Lerp(start,finish,i)

end

NOTE: if you wan’t to lerp a model, try to lerp primaryPart and connect rest of model to it via weld or use SetPrimaryPartCFrame

I just decided to use MoveTo for some models and PivotTo for others depending on whether they work. Thanks for your help though!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.