How Would I Make an Effective Node System for a Subway/Train?

Hey guys,
So I don’t really use tweening but recently I’ve found a need to use it to make this subway system, but I have no idea how to do it. I’ve watched a “Making a jailbreak train” video and looked at other posts but it has come to no avail. The system I want to make is where I have a train that follows a track/nodes smoothly, looking realistic.

The problem is that, well, I’m more of a builder than a programmer. I tried making a simple script but it just… well… sucks. The problem is that the white part doesn’t move to the nodes realistically.
Here’s my very basic code:

local TweenService = game:GetService("TweenService")
local part = game.Workspace.Move
local speed = 0
local node = 1

while part.Active.Value == true do
	local nodeP = game.Workspace.Modes:findFirstChild(tostring(node))
	if nodeP then
	local dis = (nodeP.Position - part.Position).Magnitude
	if dis > 5 then
		speed = dis/10
	else
		speed = dis/8
	end
	local tweenInfo = TweenInfo.new(
		speed,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.InOut
	)
	rot = nodeP.Rotation
	local position = {CFrame = CFrame.new(nodeP.Position)*CFrame.Angles(math.rad(rot.X),math.rad(rot.Y),math.rad(rot.Z))}
	local tween = TweenService:Create(part,tweenInfo,position)
	tween:Play()
	wait(speed)
	node = node + 1
	end
end

If anyone could help me develop a realistic node system for a train, that would be great. Thanks in advance!

1 Like

Your code is actually not bad. Theres not a whole lot you can really do to make it more realistic besides adding more parts in between the already existing parts. This should hopefully make it a bit more realistic.

1 Like

thats a nice snippit of code, i havent tried it myself as i dont need to tween around corners, but you should try to see if Enum.EasingStyle.Circular helps you on this one

1 Like

Is there a reason why you want to use a node system instead of bodymovers?

My current trains are implemented using bodymovers and they function okay. I’ve seen the approach discussed here a couple of times now and would like to know the considerations of using this instead of bodymovers. Are there any pros/cons?

I haven’t really worked with body movers before, but from what I can see, they rely on Roblox physics. The difference between the two is that one will always function as intended as there’s a set path, while the other is dependent on the Roblox physics which isn’t 100% reliable
(Please correct me if I misunderstood anything :slight_smile:)

I’ve tried adding a bunch of small parts, but the problem is that when the part is moving to the new node, it starts turning, and heads toward the node, but once it’s near the node the part moves sideways to get to the node, which isn’t very realistic. I’ve tried using different size nodes, etc.

Thanks for the advice, I’ll try that!

So I tried using Enum.EasingStyle.Circular, but I’m either confused or it’s not working. Another problem I just found: When the part is tweening, it starts of slow, gets fast, then slows down a lot. I have no idea why this is happening as the easing style is linear. Then with the turn, I set the easying style as circular, but it seems the same.

Here’s the code so far:

local TweenService = game:GetService("TweenService")
local part = game.Workspace.Move
local speed = 0
local node = 1

while part.Active.Value == true do
	local nodeP = game.Workspace.Modes:FindFirstChild(tostring(node))
	if nodeP then
	local dis = (nodeP.Position - part.Position).Magnitude
	if dis > 5 then
		speed = dis/4
	else
		speed = dis
	end
	local style
	if nodeP:FindFirstChild("Corner") then
		if nodeP.Corner.Value == true then
			style = "Circular"
		end
	else
		style = "Linear"
	end
	local tweenInfo = TweenInfo.new(
		speed,
		Enum.EasingStyle[style],
		Enum.EasingDirection.InOut
	)
	rot = nodeP.Rotation
	local position = {CFrame = CFrame.new(nodeP.Position)*CFrame.Angles(math.rad(rot.X),math.rad(rot.Y),math.rad(rot.Z))}
	local tween = TweenService:Create(part,tweenInfo,position)
	tween:Play()
	wait(speed-.01)
	node = node + 1
	end
end

If you could help further, that would be great.
Thanks!

I actually came across this very helpful reply to another thread that tells everything I need to know:

I agree with EchoReaper that implementing custom physics with only CFrame is a major hack and he has a quite nice compromise that will use CFrame for following the path of nodes and constraints to preserve Roblox physics.

sorry if this became off-topic, I’ll be gone now