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

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
4
Answered by
cabbler 1942 Moderation Voter
7 years ago

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
0
What a god greatneil80 2647 — 4y
Ad

Answer this question