Hi people! :D
I want to move a model from it's original position to the goal I set, but take time to get there. Let's say I want it to take 5 seconds (any time is fine) to get there. I would use tweening, but I'm moving a model if you noticed that I used a function from a Model. I would use tweening, but it doesn't work with models and I just want to stick with using SetPrimaryPartCFrame function. If you don't know what that is, SetPrimaryPartCFrame is a simple function that uses CFrame to move a model. (I know I could also use the :MoveTo function, but that's for moving the primary part and only the primary part) So my question is how could I possibly add a time that it takes for a model to get from the starting position to the end?
Here's the code I wrote: (i didn't put it anywhere because it's just one line :P)
script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(68.92, 2, -19.63)) --Where would I put the time?? Or how?
You can use a function of CFrame called CFrame:lerp() which lets you move the model/part towards the destination by the percentage value you specify.
So if you were to do Part.CFrame = Part.CFrame:lerp(CFrame.new(100,0,0), 0.3)
with the Part being at 0, 0, 0
, it would set its position to 30, 0, 0
local model = script.Parent.Parent local dest = CFrame.new(89.92,2,-19.63) for i=0,1,0.1 do wait(.5) model:SetPrimaryPartCFrame(model.PrimaryPart.CFrame:lerp(dest, i)) end