Learn by making things

Racing Game Update - Recursive Functions and Stylish Hovercars

I’ve finally solved my intersecting track problem. My first solution involved generating the road in multiple passes. First the generator would do a “flat pass” and lay out road segments on the same plane, freely overlapping. Then it would identify points where the track overlapped and cache some information about those points for the “height pass” which would add hills and valleys to the road while paying special attention to the intersection points and keeping the overlapping sections separated by a minimum clearance value.

It was overly complicated and didn’t work.

So I tried a different solution which is almost the exact opposite: generate the track piece-by-piece evaluating each step and proceeding only if the path is clear. To accomplish this I used recursively nested coroutines, allowing a certain number of “tries” at each step before backtracking to a previous one. I enjoy solving problems with recursion and had a lot of fun writing this algorithm. Here’s a video of the new track generator in action, I find it quite satisfying to watch.

I also created a texture for the hovercar from the last update!

stylish hovercar