Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to add a time to SetPrimaryPartCFrame?

Asked by 6 years ago

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?
0
Consider looking into CFrame:lerp() Griffi0n 315 — 6y
0
keep cframing closer until you reach the goal. aka use lerp. cabbler 1942 — 6y

1 answer

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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
0
That worked!!! Thank you soooo much! Chez_Guy 67 — 6y
Ad

Answer this question