Using Algorithms To Create Riders Republic’s Trail Network
By Staff Reports
(Ubisoft)– At the 2022 Ubisoft Developers Conference, Senior Houdini Artist Igor Kharitonov spoke about creating the procedurally generated trails in Riders Republic. To create the game’s extensive network of interconnecting trails, the team initially used a pathfinding method to build a road between two points of interest on the landscape. The pathfinder algorithm is seemingly simple: a designer assigns a Point A and Point B on the map, and the algorithm creates the most optimal path possible, while taking into account the confines of the landscape, curvature constraints of the path itself, and obstacle avoidance. The generated trail would, in theory, get players from Point A to Point B without making them ride straight up a mountain, take an impossibly sharp turn, or run into a tree or off a cliff. However, the trajectories generated were unsuitable for the needs of Riders Republic’s gameplay, as the pathfinding algorithm made it difficult for the team to add track elements like ramps and bridges that make bike racing fun, so the team had to look for an alternate solution: genetic algorithms.
In Riders Republic, the genetic algorithm would take generated trajectories – upwards of hundreds of thousands of options – and sort each one by its quality. It then randomly pairs two top-performing roads (think of them as the parents), extrapolate the most ideal sections within each path, then merge the two to create an improved trail (the child). This process would then repeat until the development team had a trail that was rideable and fun for players. We spoke to Igor Kharitonov about the challenges of designing a landscape inspired by real-life national parks, and how the team was able to shape the algorithms to best suit Riders Republic’s gameplay.
At the 2022 Ubisoft Developers Conference, Senior Houdini Artist Igor Kharitonov spoke about creating the procedurally generated trails in Riders Republic. To create the game’s extensive network of interconnecting trails, the team initially used a pathfinding method to build a road between two points of interest on the landscape. The pathfinder algorithm is seemingly simple: a designer assigns a Point A and Point B on the map, and the algorithm creates the most optimal path possible, while taking into account the confines of the landscape, curvature constraints of the path itself, and obstacle avoidance. The generated trail would, in theory, get players from Point A to Point B without making them ride straight up a mountain, take an impossibly sharp turn, or run into a tree or off a cliff. However, the trajectories generated were unsuitable for the needs of Riders Republic’s gameplay, as the pathfinding algorithm made it difficult for the team to add track elements like ramps and bridges that make bike racing fun, so the team had to look for an alternate solution: genetic algorithms.
In Riders Republic, the genetic algorithm would take generated trajectories – upwards of hundreds of thousands of options – and sort each one by its quality. It then randomly pairs two top-performing roads (think of them as the parents), extrapolate the most ideal sections within each path, then merge the two to create an improved trail (the child). This process would then repeat until the development team had a trail that was rideable and fun for players. We spoke to Igor Kharitonov about the challenges of designing a landscape inspired by real-life national parks, and how the team was able to shape the algorithms to best suit Riders Republic’s gameplay.
When designing a racing/extreme-sports game like Riders Republic, would you typically create the roads or the landscapes first? How was the process altered by using real-world settings?
Igor Kharitonov: In our approach, we were creating the landscape first, adding in iconic real-life National Park trails to the world. Then, the roads and tracks were sculpted on the existing terrain. Geology itself was adopted to provide the needed amount of slope, meaning that in Riders Republic, slopes are much steeper than in the real world.
However, when designing our racing tracks, we realized that not only do they follow underlying terrain, like ordinary roads, but also possess some features – like artificial bumps, for example – that make them more interesting to ride.
How did you determine the starting and ending points for each trail?
IK: There was a huge amount of work done by the world team to design the road/trail network on a macro scale. Some points of interest were chosen on the map and then connected with each other. Then each connection was processed by a road generator and replaced by actual roads/tracks.
What data did you use to determine if a turn was too sharp or a slope too steep? How did you calculate the best trail possible for players?
IK: Depending on the property, various mathematical equations can be used. To measure the sharpness of turns, we calculated the curvature of the trajectory in each point and then inverted it to get the turn radius. Slope was calculated as a partial derivative on a terrain height field.
In the early stages of development, there was no goal to find the best possible trail for players. We wanted to generate a trail that met the desired requirements, which ultimately translates to good gameplay. To obtain these results, we used the genetic algorithm that borrows ideas of evolution from nature and operates on concepts of population, selection, crossover, and mutation. With this algorithm, we could start with some trajectories, randomly generated between starting and ending points, and then evolve and converge to something meaningful.
How did the genetic algorithm determine the best parts of the parent trajectories that should carry over to the child?
IK: There was no goal to precisely extract the best parts of the parent tracks to promote them to the child. This is not exactly how a genetic algorithm works. Instead, we perform an evaluation of all randomly generated trajectories and assign a corresponding score. The bigger the score, the more elements that we want a trajectory contains. Then, this score is used to guide the selection process that defines candidates for crossover. The bigger the score, the more chances a trajectory has to be selected and crossed with another one, therefore the more chances its parts will be promoted to the next generation.
You mentioned the genetic algorithm was run hundreds of thousands of times. How do you know when you’ve finally created the perfect trail that will maximize fun for players?
IK: The quality of the result of a genetic algorithm depends on a number of iterations, which theoretically can be infinite (with the infinite time to compute). Of course, with more and more iterations, the quality increase starts to saturate and stabilize. This allows us to limit the number of iterations without sacrificing quality too much. The number of iterations was one of the hyperparameters of the system that was chosen by balancing between performance and quality of the solution.
How does the end-result trail affect what kind of obstacles, such as ramps and bridges, you can add?
IK: Additional elements like ramps and bridges were placed on the track according to some rules, which required a specific slope, curvature, and width of the track. These rules were part of the track description. Of course, it was essential to have segments of the track with desired characteristics to be able to place the element. Therefore, it was important to guarantee that general parameters of the track responsible for its shape and parameters for the artificial elements match each other.
Riders Republic is available on Xbox Series X|S, Xbox One, PS5, PS4, Stadia, Amazon Luna, and PC. If you’d like more on Riders Republic, read about the exclusive gTV documentary or the recent Prada collaboration.