Friday Facts #378 - Trains on another level

Posted by V453000 on 2023-09-29

The code refactor of rails presented last week is great, but the motivation for such a task wasn't quite just some shape changes for rails.

As explained last week, we can now define any kind of rail shape, and we had some very specific shapes in mind all along...

Over or under?

We want multi-level crossings for trains, but how? Bridges or tunnels?

At first it would seem like going underground is the safer bet - we already have experience with belts and pipes doing that. Simple - we draw the entrance and the exit, the middle is magically connected, and that's it?

  • The second layer of rails should also be able to use curves and rail signals, otherwise it would be quite limited.
  • Sometimes you already want to interact with items inside of underground belts, with trains this would be a lot worse as they can run out of fuel, stop at signals etc.
  • Building curves, signals or interacting with trains inside of a tunnel probably means we need to be able to walk inside.
  • If we can walk in a tunnel, biters and robots should be able to as well.
  • If tunnels can have curves, how could you tell which tunnel entrance connects to which exit when looking from the outside?
  • Tunnels "over" water don't quite feel right.
  • Drawing tunnels would be surprisingly difficult as we would need to do some expensive masking that Factorio isn't currently capable of.
  • And more...

The idea of an elevated rail seems to have much more potential, although drawing in an upper layer certainly won't be easy either.
Also, you just want to boldly see all of your trains in their full glory instead of hiding them somewhere in a cellar!

Such an idea would consist of:

  • Rail ramp - The transition between the lower and upper layer.
  • Elevated rail - Tracks buildable above most things.
  • Rail support - Elevated rails would need supports at some intervals.

Elevated rail system pieces. These were the "greybox" graphics to test the gameplay of the new rail shapes and the ramps, before the final graphics were created.

Elevated rails

I know you've already scrolled down to see the ramps instead of reading this but it just felt weird not to put a paragraph here.

When we thought about the visual design with Albert and Earendel, we wanted the ramp to be heavy and industrial, but at the same time not quite perfectly stable and rigid. After multiple iterations we have arrived to this combination of a solid concrete base combined with an upper metal structure.

The concrete base helps clearly show where the ramp touches the ground, while in contrast the metal part has a lot of holes so you could see entities placed behind the ramp most of the time. The metal is painted red, as mostly the only other red entities in Factorio are related to trains, it helps the elevated rails belong to the train family, and stand out in the factory - as they should with their height.

The rail ramp is the new longest entity in the game at 16 tiles long and 4 tiles wide, so you will need to consider where and when to place it. It can only rotate in 4 directions.

The rail support follows the style of the ramp, but with the difference that it can be rotated in 8 directions.

It has a roughly 4x4 collision box, with the rotated ones all having the same shape.

The elevated rails can be built between ramps, held by rail supports along the way.

The elevated rail can be constructed above anything except tall entities (rocket silo, roboport, big electric pole, etc.).

They have exactly the same rail shapes as the new ground rails do, and signals can be attached to the elevated rails.

There are fences which help visually distinguish the elevated rails from ground rails, you can also see how they disappear on track crossings.

In practice replacing a colliding connection inside of a T junction with a ramp going around it can already help a lot.

With the ramp being long and since we have "only" two layers, building a fully multilevel junction can get rather large, but the throughput potential is massive.
It's worth noting that it's not just the level separation that helps. It's also the fact that we don't need chain signals, so we can shorten the distance between normal rail signals a lot as we don't need to guarantee there's enough space for a train "behind the junction".

Specifically in arrays of train stops, having the exit and entrance on different levels is a game changer.

There is a very special patch that draws under terrain which is visible only in places where the ramps or supports touch water.

In case you decide to route your rails through a lake because why not, islands can become opportunities for multi-level crossings.

Building something elevated can be done with the rail planner. Either you can press a keyboard shortcut to switch the destination layer or you can start the rail planner on a ramp, rail support, or an elevated rail.

But one day, kovarex said "Why doesn't the rail planner just snap to the rail you're pointing at?"
And since that day it does, rail planner "just connects" to any rail you pick, including between ground and elevated levels.
This also massively helps mitigate issues related to the rail planner having more directions.

The rail planner can often find connections you wouldn't even expect to be possible, which can be mesmerizing to play with... a result, this can happen a lot quicker than you'd think.


Allowing trains to cross paths on different levels has been one of the most requested features for a very long time. We had always felt it makes perfect sense, but trains in Factorio would rarely ever get into serious enough throughput issues to justify adding elevated rails.

The expansion changed this landscape quite a bit though. If we expect players to generally build larger factories than in the base game, train throughput could become an issue, and since you are expected to travel away from the home planet, having a train system that doesn't deadlock would be more important than ever before.

It's not hard to guess that implementing this would require a lot of time, and working on the expansion behind closed doors allowed us some breathing room where we could make bigger experiments.

Between boskid with the mechanics and posila with the drawing code, just the programming took a few months. On the graphics side, we could reuse a lot of initial Blender setup from the rework of ground rails, but that didn't get us very far. The ramps were simply large objects, while the rail supports are a hive of optical hacks as they need to fill their collision boxes. Both the ramps and supports were reworked multiple times to finally get the result that would look and function well.

Especially because of the elevated rail fences, the required sprite count grew very rapidly. This made me use all the tricks in our Blender book and even add completely new Blender Python tools that mostly help with organizing and rendering large amounts of outputs. I got the final iteration to about 90% completion but then it just became too much.

Jerzy already had experience with rail graphics, so I had asked him to help me by finishing the last details and texturing, and then he handled all of the signals and remnants again. It's hard to overstate how much bravery and mental fortitude was required to "just" jump into the Blend file of the elevated rails, and I'd like to thank him for that, again.
You can probably see from the above images that he did excellently. :)

Between Earendel on concept art, me on most of the 3D process, Jerzy on finishing and together with Albert on re-evaluating multiple major iterarions, the graphics took about 9 months to make. Perhaps we could have taken some simplified route trying to make tunnels work, but we believe the elevated rails offer better gameplay beyond comparison.
Yet again we can confidently say that properly focusing on some features in the expansion rather than trying to shove more things into 1.0 was a very good decision.

All of the elevated rails will be only available with the expansion executable. Their technology can be researched using Production science packs without the need to go to space or any planets. Elevated rails be will one of the standalone official mods next to Quality and Space Age, so you can play a vanilla-like game with just the elevated rails for example, or other mods can just depend on Elevated rails.

As always, we are looking forward to all the feedback you are about to elevate.