Model/PrimaryPart to the given position. If a primary part has not been specified then the root part of the model will be used. Because the root part is not deterministic, it is recommended to always set a
Model/PrimaryPart when using MoveTo.
If there are any obstructions where the model is to be moved to, such as
Terrain or other
BaseParts, then the model will be moved up in the Y direction until there is nothing in the way. If this behavior is not desired,
Model/SetPrimaryPartCFrame should be used instead.
Note that rotation is not preserved when moving a model with MoveTo. It is recommended to use either
Model/SetPrimaryPartCFrame if the current rotation of the model needs to be preserved.
This sample demonstrates how Model:MoveTo avoids collisions.
A simple two part Model is created, and its PrimaryPart is set. An large obstruction part is placed next to it.
After 5 seconds Model:MoveTo is used to direct the model to move inside the obstruction part. However, as MoveTo will not move a model inside of an obstruction the Model is moved up on the Y axis and placed above the obstruction.
-- define two Positions local startPosition = Vector3.new(-20, 10, 0) local endPosition = Vector3.new(0, 10, 0) -- create a simple model at the startPosition local model = Instance.new("Model", game.Workspace) local part1 = Instance.new("Part") part1.Size = Vector3.new(4, 4, 4) part1.Position = startPosition part1.Anchored = true part1.BrickColor = BrickColor.new("Bright yellow") part1.Parent = model local part2 = Instance.new("Part") part2.Size = Vector3.new(2, 2, 2) part2.Position = startPosition + Vector3.new(0, 3, 0) part2.Anchored = true part2.BrickColor = BrickColor.new("Bright blue") part2.Parent = model -- set the primary part model.PrimaryPart = part1 model.Parent = game.Workspace -- create an obstruction at the endPosition local obstruction = Instance.new("Part") obstruction.Name = "Obstruction" obstruction.Size = Vector3.new(10, 10, 10) obstruction.Position = Vector3.new(0, 10, 0) obstruction.Anchored = true obstruction.BrickColor = BrickColor.new("Bright green") obstruction.Parent = game.Workspace wait(3) -- attempt to move the model to the obstructed endPosition model:MoveTo(endPosition)