How can I generate roads such as those in the game Twisty Road?
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#? As an amendment suggested by Alexandre Vaillancourt, 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.
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.
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport