Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

1 comment

0

There is a function on CFrames called Lerp, never used it so I can't explain any more.

1 answer

✓ Accepted answer

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))

This discussion is preserved as it was. New answers, comments, and votes are closed.