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 8 years ago
Edited 8 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:

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

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
8 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.

1local ppart = model.PrimaryPart
2local original = ppart.CFrame
3local goal = CFrame.new()
4local inc = 1/100
5 
6for i=0,1,inc do
7    model:SetPrimaryPartCFrame(original:lerp(goal,i))
8    wait()
9end
0
What a god greatneil80 2647 — 5y
Ad

Answer this question