Hi, I’m trying to make an endless runner with procedural roads that curve and go up and down. I have done the movement and everything but I don’t know how I could generate procedural roads. I was thinking of doing premade levels which get picked randomly and then connecting them but I don’t know how to make them connect. I am using this path creator to make the roads that the player follows: Bézier Path Creator | Utilities Tools | Unity Asset Store.
I am pretty new to Unity so I would appreciate some help.
Hey, I did this not to long ago with a tunnel system. Something to consider/accept before you do this. You lose any optimizations you would get from having the roads prebuilt and marked as static.
How I went about about it is reduced the problem into to parts:
generating points (Vector3’s) that will be used for building the paths (ill focus on this)
building the roads from the paths ( iwont focus on this as its your own personal style)
for generating the points, i used recursion
bool FillPath(Stack<Vector3> currPath, otherParams...){
// 1) check if my path is complete, return true if yes
// 2)for each candidate point to add:
// 2.1) if point is legal:
// 2.1.1) currPath.Push(point)
// 2.1.2) if FillPath(currPath, updatedParams) return true
// 2.2.3) else currPath.Pop()
// 3) return false
}
basically the base conditions of the recursion is either completing the path or violating the rules of the path. By the end, the stack should have all the points of interest. I initially generated new paths as they became necesary during gameplay with multithreading to avoid hitting the framerate when needing to generate new paths, but regretted it later, which leads to my last tip. consider if you coud realistically generate N paths on game start and just loop through them if more than N paths end up being needed. you would still have variability across scene loads.