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

How can I make a train follow railroad tracks & curved tracks. Like Jailbreak?

Asked by 5 years ago
Edited by SerpentineKing 5 years ago

I have these Railroad tracks! They're pretty long and pretty curvy at the same time! Download the Video

THE CODE:

local RunService = game:GetService("RunService")
local Speed = .01
local model = script.Parent

function GetTime(Distance, Speed)
    -- Time = Distance / Speed
    local Time = Distance / Speed
    return Time
end

local Points = {}
local function movemodel()
    for i = 0,1,Speed do
        wait()
        if not model.PrimaryPart then
            break
        end     
        model:SetPrimaryPartCFrame(Points[1].CFrame:Lerp(Points[2].CFrame,i))
    end

    for i = 0,1,Speed do
        wait()
        if not model.PrimaryPart then
            break
        end     
        model:SetPrimaryPartCFrame(Points[2].CFrame:Lerp(Points[3].CFrame,i))
    end
end

movemodel()

However, when it takes a few turns with the other train cars, they won't maintain the same speed when turning and moving straight. Causing them to collide and making it weird to move!

0
Can you please use the code blocks properly? Only code goes into them and the tildes are supposed to be on their own lines  SteamG00B 1633 — 5y
0
As for what I can see there right now, you do have the right idea using CFrame:Lerp() SteamG00B 1633 — 5y
0
EDIT: Added Code Blocks / Embedded Link SerpentineKing 3885 — 5y

Answer this question