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

How to CFrame Lerp a model?

Asked by 4 years ago
Edited 4 years ago

I have some code, which makes a object follow a path of parts. This is for a rollercoaster. I was wondering if anyone would able to help me so that:

  1. It moves a model instead of one part
  2. Anyway to make it more efficient
  3. Is there anyway to get all the track parts without having to manually write every one

Thanks!

local p1 = script.Parent:WaitForChild("Track1")
local p2 = script.Parent:WaitForChild("Track2")
local p3 = script.Parent:WaitForChild("Track3")
local p4 = script.Parent:WaitForChild("Track4")
local p5 = script.Parent:WaitForChild("Track5")
local rp = script.Parent.CarFront


while wait() do
    for i = 0,1,.05 do 
        rp.CFrame = p1.CFrame:lerp(p2.CFrame,i)
        wait(0.0001)
    end
    for i = 0,1,.05 do 
        rp.CFrame = p2.CFrame:lerp(p3.CFrame,i)
        wait(0.0001)
    end
    for i = 0,1,.05 do 
        rp.CFrame = p3.CFrame:lerp(p4.CFrame,i)
        wait(0.0001)
    end
    for i = 0,1,.05 do 
        rp.CFrame = p4.CFrame:lerp(p5.CFrame,i)
        wait(0.0001)
    end
    for i = 0,1,.05 do 
        rp.CFrame = p5.CFrame:lerp(p1.CFrame,i)
        wait(0.0001)
    end
end

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

use :MoveTo.

This function will move an entire model to the block's position, so you may have to create a block at the designated position, don't use:

track:MoveTo(part.CFrame)

It is wrong, use:

track:MoveTo(part.Position)
Ad

Answer this question