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

How to make a CFrame Roller Coaster?

Asked by 5 years ago

I would like to make a coaster follow a path of bricks using the position and rotation of the part and cframing the train along the path.

See Image below: http://i.prntscr.com/132lorrkS2Ko-c0r20eRZA.png

I have this code which allows it to be cframed around the track facing foward but it ends up derailing as there is too much pressure on the direction. Would there be anyway to make it follow the parts?

Thanks.

local Model = script.Parent

for i = 0,1,.001 do
Model:SetPrimaryPartCFrame(Model:GetPrimaryPartCFrame() *CFrame.new(0, 0,-0.5))
wait()
end


0
This is not a optimal suggestion, but remember the roller coaster set that stamper tools has before they got removed? Well if you do, that's good and if not, well pull up a wiki article if you're interested. Based on the way stampers worked (inserting a model outside of the game into the game) there has to exist models of the roller coaster set somewhere. I'd suggest you try something else first. SuperSmartYoshi 17 — 5y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

First, I would name the rail parts in order of how they are placed (1 being the start). Then, I would give each rollercoaster segment an invisible PrimaryPart (that is located where the segment meets the rails), and then also name the rollercoaster segments from 1 to 4 (1 being the furthest back & 4 being the furthest forward). After this, you can CFrame each segment with this method to move it smoothly between rail parts. With all this in mind, something like this as an outline could help get you started:

local function StartCoaster(Coaster,RailModel)
    local Rails = RailModel:GetChildren()
    --sort rails table from lowest number name to highest number name:
    table.sort(Rails,function(a,b)
        return tonumber(a.Name) < tonumber(b.Name)
    end)
    for RailNum,Rail in pairs(Rails) do --go through ordered rails
        for _,Segment in pairs(Coaster:GetChildren()) do
            local GoalRail = Rails[RailNum + tonumber(Segment.Name)]
            TweenModel(Segment, GoalRail.CFrame) --handle tweening here
        end
        wait(TweenTime) --change to time taken for tween
    end
end

StartCoaster(workspace.Coaster, workspace.RailParts)

Inside this function, it finds the next rail for each segment (segment number + RailNum) and tweens that segment to the desired rail. As RailNum increments, the coaster advances along the rail. This isn't tested and probably has bugs, but it should help as an outline for your solution.

0
Thanks I wlll try this out! JDCustard 0 — 5y
0
Using this kinda, but not working. Help? HeadlessDeathSpeaker 9 — 4y
Ad

Answer this question