Every racing game should have a road and there could be different approaches to solve it. In this post I’m going to talk about what we did in Fuel Renegades to achieve a great solution.
At first we decided to have a “tile based” track similar to Trackmania. But it required a lot of work for the artists to have enough tiles to consider it complex. In the process of looking for another solution we found an Unreal Engine tutorial about road generated as an spline.
How to create a spline based road.
To attach a mesh to the spline we need what is called in Unreal Engine a SplineMeshComponent.
A SplineMeshComponent is a mesh that can be deformed between every pair of points of a spline as shown in the image:
All operations done to create the road should be in the Construction Script if you want it to be edited in real time in the editor.
In the Unreal Engine documentation for SplineMeshComponent there are some variables that can me manipulated by instances such as position, tangent or up and forward direction.
Position and tangent are used locate and rotate the piece, both of them have a start and a end part to determine the shape of the spline mesh.
The up and forward direction are used to set the orientation of the mesh as it being one of the major inconveniences of the tool. If you want a basic road orientated always from the ground up you can set the up as simple as the World Up, but there would be some cases in which you would like to perform a loop for example.
In that case, you must get the up vector from the two spline points containing the SplineMeshComponent and set it as the start and end up.
Some extra details.
The road now is very malleable but there some aspects that gives more variety to our road, those are roll rotation and scale.
Road Generator for Fuel Renegades.
This tool has speed up the process of creating new levels for our game as we can create a new road every day with great results. It has always be though to be easy to use by designers and scalable for programmers.
Road Generator for programmers.
The road generator is a set of pieces created for every pair of spline points.
This is the function that we called to create a new piece of road:
It does pretty much what has been explained at the beginning. The parameters define a basic creation of the piece and returning the recent created mesh can be used to add extra information such as visibility.
Road Generator for Designers.
The Road Generator has been created to achieve most of the necessities of the designers, apart of the spline tool, some of them could be add guard rails for collisions or triggers to perform out of road respawn.
The guardrails are divided in two parts visibility and collision. This allow artists to create different types of guardrails without worrying about collision.
The rail guards can be disabled at every piece as well of many other options given per instance of mesh in the Road Data Array:
There are a hollow cube following the road used to perform overlap collisions and check when the player has got out of the road. This is the trigger mesh:
For edit every part without being confused of which part you are currently modifying there are a boolean given to draw the index of each in the defaults variables.
Road Generator for Artists.
Artists can edit which mesh and meterial display at every piece of the road or even the whole road changing the default items. For example, changing the whole main road material:
And using the Road Data Array can edit individually each piece overriding the defaults. Example:
At our current stage of development the major problem from the art part has being the stretch that suffers every affecting the uv’s in both axis and deformations.
Working with spline mesh is very tedious at some times. The mesh could not blend as you want and it is very common and hard to smooth.
This approach for the road problem has been the best we could imagine for speed up this process. Artists and designers have worked quite well since it is working and the have had more time to focus on environment or guide the player through the race.