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

How would I tween a model (PrimaryPart - tweening)?

Asked by
nanaluk01 247 Moderation Voter
6 years ago

How would I tween a model (PrimaryPart - tweening)?

Alright, I know the method :SetPrimaryPartCFrame(), and I know how to tween single parts.

What I do not know how to do, is how I would tween an entire model, similarly to doing :SetPrimaryPartCFrame to a model with a placement system. (What I mean is that I want to tween the entire model)

I have no idea what to do in order to tween the entire model relative to it's PrimaryPart

I have this coding for my single-part tweening:

ntarget is specified as the part I want to tween, earlier in the script.

local TimeForObjectToTweenBack = 0.2

function TweenPart()
    if ntarget ~= nil then  
        local goal = {}
        goal.Position = PrevPosition --PrevPosition is also specified earlier in the script, don't worry. :|

        local tweenInfo = TweenInfo.new(TimeForObjectToTweenBack)

        local tween = TweenService:Create(ntarget, tweenInfo, goal)

        tween:Play()
        wait(TimeForObjectToTweenBack)
        ntarget = nil
    end
end

Any help is greatly appreciated!

0
There is a function on CFrames called Lerp, never used it so I can't explain any more. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
1
Answered by
CootKitty 311 Moderation Voter
6 years ago
Edited 6 years ago

Yeah, use lerp.


Example:

local start = part.CFrame
local finish = start * CFrame.new(10,10,-5) --idk, numbers

for i = 0,1,0.03 do
    part.CFrame = start:lerp(finish, i)
    wait()
end

So in this example, we're moving from start to finish, by percentage i, and the percentage i is going from 0 to 1, 0 being 0% and 1 being 100%.

I hope that makes sense.

start:lerp(finish, delta AKA Percent)


Time specific

As you can tell, it's hard to judge how much time it'll take for the lerp to finish if you use wait. Honesty, I don't want to explain this, and I don't have to, so here's a link to ScriptGuider's video. He'll explain it.

model:SetPrimaryPartCFrame(start:lerp(finish, percent))
Ad

Answer this question