Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a CFrame Roller Coaster?

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


1 comment

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.

1 answer

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.

2 comments

0

Thanks I wlll try this out!

0

Using this kinda, but not working. Help?

This discussion is preserved as it was. New answers, comments, and votes are closed.