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

How do you move and/or rotate an entire model smoothly?

I've been wondering this for a while, but I haven't really had a need for it until my current project. I know how to smoothly move singular parts:

a=game.Workspace.Part
for i=1,10 do
a.Position=a.Position+Vector3.new(1,1,1)
end

I also know how to move an entire model via :MoveTo(), as well as a small understanding of the PrimaryPart property.

But I am not sure how to implement these two concepts together.

I assume I will have to use :MoveTo(), as well as :SetPrimaryPartCFrame(), but the real kicker for me is how to implement a smooth Vector3/CFrame change.

As for rotation, I'm just completely lost.

Now, I may be missing something VERY obvious, and if anyone know what this is or knows how to do this, I would really appreciate a wiki link or tutorial. An example script would be nice, but i find it better for my understanding to actually try to learn it for myself.

1 answer

✓ Accepted answer

CFrame the primary part and it will move the entire model accordingly. For a smooth movement you have to use a lerp loop. Lerp puts a original value towards a goal value by a percentage you specify. If you smoothly change that percentage, it cframes smoothly over time. You just use the "i" as an actual value.

local ppart = model.PrimaryPart
local original = ppart.CFrame
local goal = CFrame.new()
local inc = 1/100

for i=0,1,inc do
	model:SetPrimaryPartCFrame(original:lerp(goal,i))
	wait()
end

1 comment

0

What a god

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