Here is a link to see the gameplay: https://www.youtube.com/watch?v=03PzsgO-uAM

How could I procedurally generate the path upon which the ball rolls in Unity/C#?

I know I could model distinct pieces of the road in Blender and import them into Unity as prefabs. My problem is, I genuinely have no idea where to start when it comes to programmatically generating the whole road out of those prefab sections in a cohesive manner, such that the road is built seamlessly and randomly with twists and turns in three-dimensional space.

I would appreciate any insight you could provide. Thank you.

  • \$\begingroup\$ I can't really offer you a full answer as it's not something I've done myself yet but what you want is Spline--based procedural geometry youtube.com/watch?v=o9RK6O2kOKo also github.com/JPBotelho/Unity-Road-Generator \$\endgroup\$ Commented Jun 12, 2018 at 11:45
  • \$\begingroup\$ @Pheonix2105 Thank you very much. The Spline-Based Procedural Geometry video is immensely helpful. \$\endgroup\$
    – user117136
    Commented Jun 12, 2018 at 18:51
  • \$\begingroup\$ Glad I could help, good luck! \$\endgroup\$ Commented Jun 12, 2018 at 19:12

2 Answers 2


So, there are a few ways to do this theoretically, but I'll detail the one that you've been presented with. Firstly, you'd come up with a system for separating the roads into pieces. In Twisty Road, it looked like there were some straight strips that didn't bend much. Those are ideal locations to join the "seams" of your road gameobjects. What you would need to do is create bendy road prefabs of reasonable length that begin and end with straight portions.

Programmatically, you store these prefabs in an array. If I were you, I would give these prefabs two child gameobjects. These children will be start and end hinges. Move them to the ends of your roads, and then you'll be able to link your roads together on the fly. In your map generator code, you Instantiate a random road. Then, you Instantiate a second one and set its START hinge transform.position to the same as the previous road's END hinge transform.position. Recursively do this however many times as you'd like and voila. You have your procedurally generated bendy road map.

You could even rework this to start building more roads as the player progresses to its like a never-ending road if you wanted.

  • \$\begingroup\$ Thank you. So what you are saying is that the only pieces of road that are joined together should be straight ones and that any bendy piece would be best straightened out before joining a new one? And that will be accomplished by putting a gameobject on the start and end of each piece to reference the transform of on the fly? Do you think that method, Spline-Based, is the easiest/most efficient/best way to do it, or do you have any other methods you might recommend? Thanks again. \$\endgroup\$
    – user117136
    Commented Jun 13, 2018 at 1:01
  • \$\begingroup\$ I do believe Spline-based to be the most logical solution to the problem. Its also easier than trying to generate a 3 dimensional curve and mapping a road to it, although that could also be done. I wouldn't know exactly how to go about it in Unity, though. \$\endgroup\$ Commented Jun 14, 2018 at 12:57

I know this question is old but there is a Unity package called the Path Creator Tool that solves this same exact problem. You can check out how to use it here: https://www.youtube.com/watch?v=saAQNRSYU9k Consider becoming a Patreon to the guy that made this because this is a pretty complex tool and he was generous to make free for us all to use. Here's the creators Patreon page.

  • 1
    \$\begingroup\$ This is currently considered a "link only" Answer. Could you explain how to use the linked package here? \$\endgroup\$
    – Vaillancourt
    Commented Sep 30, 2020 at 1:37

You must log in to answer this question.