To do this, you would use the SetPrimaryPartCFrame function of models and the lerp function of cframe, and of course, a handy for loop.
SetPrimaryPartCframe and Lerp
The set primary part cframe function differs from directly setting a model's primary part in the manner that it moves the entire model rather than just the primary part.
Lerp, or linear interpolation is a way of smoothing changing an object's cframe between two points, the basic function of lerping can be summarized here:
local function lerp(a,b,alpha)
return a + (b-a) * alpha
end
Application
With that said, you can do the following:
button = script.Parent
model = script.Parent.Parent.Parent.Gate
local pos = Vector3.new(-22.95, 33.3, 148.5)
local start = model:GetPrimaryPartCFrame()
button.ClickDetector.MouseClick:Connect(function()
for a = 0,1,0.05 do
local p = cframe.lerp(start,CFrame.new(pos),a)
model:SetPrimaryPartCFrame(p)
wait()
end
end)
Hopefully this helped!
4 comments
What is the question? What is the problem with the code?
The problem is trying to get it to go upwards smoothly. I'm not sure how I would tween a model.
Best way to tween models is to have a non collidable, invisible and anchored part as a "root" and weld the model to that part via a Motor6D, unanchoring the model later. Then you tween root with a tweenservice.
Thank you so much.