Spline-based road tool in Unreal Engine 4.

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.

A spline is easy to manipulate by everybody and Unreal has a great component and editor which we can use.

spline gif
Spline Component

To attach a mesh to the spline we need what is called in Unreal Engine a SplineMeshComponent

SplineMeshComponent is a mesh that can be deformed between every pair of points of a spline as shown in the image:

spline_mesh
Mesh blending between spline points.

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.

spline_mesh_loop
Loop

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.

spline_extra
Extra details

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.

roadgenerator
Road Generator

This is the function that we called to create a new piece of road:

buildtrack
Build Track Element

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.

buildtrack_extra
Extras for Build Track Element

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.

guards
Collision – Visibility

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:

roaddataarray
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:

Inconveniences found.

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.

art_error2
No stretch.
art_error1
Stretch affecting uv’s and deformation.

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.

blend
Blending problem.

Conclusion.

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.

1 thought on “Spline-based road tool in Unreal Engine 4.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close