Train buggy on a track with many parts

I am making a train using roblox physics, I have tried many variations.
Right now I am using this version:


On a track like this:

this happens:


it jitters and its shaking and vibrating.
on a track like this:

where the parts are all max length 2048 it works smoothly

so the probem is that when parts get connected the physics glitch for some reason and that happens, I know that I can use max length parts but I am trying to make curves and there I need to use multiple smaller parts which lead to the train shaking, is there a way to make the physics not bug when connecting two parts? or make it connect smoother? I hope you get what I mean

1 Like

My guess is that it probably has to calculate the physics for each individual object instead of one long object. It happened to my railway game before i migrated to CFrame.

You can use CFrame Train system to solve all physics-related issues (but raycasting is necessary for sensors and stuff)

So yeah, if you need help with making a CFrame Train system i can help you. I also have a node layer so you can add new railway paths on the fly.

Hi, before making this post I actually made something.


it uses a linearvelocity, what was or is your idea, just using a linear interpolation between the nodes and use CFrame to move the train?
I would be very grateful if you could give me a brief explanation of how your CFrame Train System works.

Linear interpolation is what i use, as it doesn’t lag or derail. I’ll use one of my trains as an example.

function Move(target, deltaTime)
	local curNode = target.Current.Value
	local nextNode = target.Current.Value.NextNode.Value

	local distanceTraveled = (curNode.Position - target.Position).Magnitude
	local sectionLength = (curNode.Position - nextNode.Position).Magnitude
	local newAlpha = ((distanceTraveled + curSpeed.Value * deltaTime)) / sectionLength

	target.CFrame = curNode.CFrame:Lerp(nextNode.CFrame, newAlpha)
	
	if newAlpha >= 1 then
		NextNode(target)
	end
end

What is target? Target is the part that moves along the nodes, think of it as a bogie.
deltaTime is the value received from game:GetService("RunService").Heartbeat
Think of newAlpha as a percentage, where 1 means it has finished 100% of it’s path and it’s travelled to the next node, and 0.5(50%) in between, and 0 at the starting position.

To get the newAlpha, you have to add the distance traveled with the speed of the train, then multiply the result by the deltaTime, and divide by the section length.

This is how my system works in a nutshell

1 Like

Thanks for the code snippet here. I know that using CFrame to move parts causes the player to just stay in place when the part is moving, do you have a solution to make the player stick to the train?

EDIT: I also have to handle the rotation of the train right? Testing rn I see it has the same rotation.
EDIT 2: Nvm I didn’t rotate the part. All good