Rvzol
(Aiden)
August 11, 2022, 12:22pm
#1
I know this is very simple but for some reason, my code moves the model above the position
local beans = math.random(1,3)
if beans == 1 then
script.Parent:MoveTo(Vector3.new(-554.617, 1.732, 66.135))
elseif beans == 2 then
script.Parent:MoveTo(Vector3.new(-554.622, 1.658, 91.649))
elseif beans == 3 then
script.Parent:MoveTo(Vector3.new(-616.309, 1.65, 125.028))
end
If anyone knows how to fix this so it won’t just move the model above the position please help.
1 Like
Valkyrop
(JustAGuy)
August 11, 2022, 12:24pm
#2
Do you mean, you want to move your model only on ‘x’ or ‘z’ axis? Without changing its height?
Check from this forum. Vector has collision detection. So, if there’s something in the way, it’ll just move upwards so you should use :SetPrimaryPartCFrame()
instead.
Rvzol
(Aiden)
August 11, 2022, 12:40pm
#4
When I used this it changes the rotation, Is there a way to fix this?
zektonn
(zektonn)
August 11, 2022, 1:16pm
#5
Use Primary Part, Like this
Note: Go to the Model Properties press the Primary Part and set it to any child of the Model
script.Parent.PrimaryPart.Position = Vector3.new(-554.617, 1.732, 66.135)
Model:SetPrimaryPartCFrame(CFrame.new(POSITION) * CFrame.Angles(math.rad(),math.rad(),math.rad())) -- put preferred angles in math.rad()
I think that would only move the PrimaryPart and not the other parts that are children of the model
Cens_r
(Censor)
August 11, 2022, 1:25pm
#9
You should use the PivotTo function for moving models. It will move the entire model to the given CFrame.
Model:PivotTo(Cframe.new(POSITION))
2 Likes
Downrest
(Down)
August 11, 2022, 1:31pm
#10
Like what @Cens_r mentioned, use the new PivotTo() function as SetPrimaryPartCFrame() is deprecated. No need for welding or unanchoring.
Since the advent of pivots, moving models is very efficient with PivotTo and doesn’t suffer from the floating point imprecisions that SetPrimaryPartCFrame did. This note is to point to the fact that developers can use the “old” method of tweening models (by proxy - you tween a CFrameValue and then have the model’s CFrame adjust according to the current value every step) now that pivots exist and SetPrimaryPartCFrame is deprecated, ridding of model tweening’s most glaring issue.
1 Like
Forummer
(Forummer)
August 11, 2022, 6:30pm
#11
I agree, setting a model’s position and preserving its current orientation is fairly trivial.
Model:PivotTo(CFrame.new(0, 0, 0) * Model:GetPivot().Rotation) --If you want to preserve the model's rotation.
2 Likes