How were the trains in Jailbreak done? [SOLVED]

Hi there, I hope you’re having a good day!

I was wondering how I could move models along a set path in a smooth way, and the one example that I thought of instantly were the Jailbreak trains. I’m not asking for any code, I just want a push in the right direction to what methods I should use as I’m not exactly sure where I should start.

Thanks!

16 Likes

I don’t exactly know how jailbreak did it, but a possible method would be TweenService. Tweens allow smooth transitions of various types and can be used on almost any use case from moving to sizing to rotating etc. To move the models, you could use Mode:MoveTo() or Model:SetPrimaryPartCFrame(). The benefit of MoveTo is that it does not require a primary part, however it will adjust to objects that are in its way. SetPrimaryPartCFrame on the other hand requires a primary part and will ignore objects that block its way, this is what you’ll want to use. The only challenge that I see here is coordination. How exactly will you move every single train car all at the same time.

Another method would be some sort of node system. The train will move to a node and the node contains data such as Rotation and Speed and which node to go to next.

4 Likes

They did not ask how to move a character along with train they want to make the train.

3 Likes

If you know that whatever you’re animating will animate in a loop (like, say, a train), then using the built-in animation system would be great. This lets the engine do the physics and interpolation for you. With tweens, you have to do a lot of extra stuff since it doesn’t use physics, so characters standing on a tweened object don’t move along with it. You also need to do an additional tween locally, since tweening it on the server alone leads to choppiness.

4 Likes

Woops misread the question, sorry.

2 Likes

Funnily enough a similar question has been asked before on the Dev Forum:

And was answered by badcc himself:

7 Likes

That is about keeping the player on the train while jumping, not about actually moving the train.

5 Likes

I recognise that, but by reading the post it seems like they CFramed the train, as well as the character:

Would recommend reading more then just the badcc post in that threat, but due to the mention of LastTrainCF and TrainCF, thought it was obvious. I apologise for not being clear enough in the first place.

5 Likes

Alright, thank you all! I figured out how to do this. Now, I know some people might be looking to do a similar thing so I’ll explain how I did it. I didn’t make a train but you could easily do so. Keep in mind that this may not be the best method but it is one that works for me.

First off you will want to connect all of your parts to one ‘Root’ part, as :SetPrimaryPartCFrame() slowly dislocates parts. After this, you can use TweenService to move the Root smoothly, which will also move any parts connected to it.

I created several parts to act as nodes and then looped through them. I tweened the model to each part.

To maintain the same speed at any tween distance, you can use Time = Distance / Speed. In my case, I did the following:

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

local NewPoint = Points:WaitForChild(""..i) -- New selected point/node
local Distance = (Raft.PrimaryPart.Position - NewPoint.Position).magnitude -- Get the distance between the current position and the next node
local Time = GetTime(Distance, Speed) -- Calculate the time
print(Time)
		
local NewTweenInfoTable = TweenInfo.new(
	Time, -- Time
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out, 
	0, -- RepeatCount (-1 = Infinite)
	false, -- Reverse tween after finishing
	0 -- DelayTime
)
-- Then you would make the Tween with the TweenInfo

To keep the player on the moving object, see this thread: Jailbreak train platform system? - #11 by tyridge77

27 Likes

Alright theres one more problem now. My carriages are separating like someone pulled the lock between the train cars. I do not know whats causing the separating train cars. I use a train system DevOfLua created. Is there anyway of preventing it? Maybe some calculations and stuff?

1 Like

How would curves work with this though, for each cart to curve on a turn?

5 Likes