-1
\$\begingroup\$

I would like to create an algorithm that generates a random track that a car can race on.

How would I best go about such an algorithm? I will be using Unity 2D, but for my project I require using an algorithm I develop myself, so I would rather not use any track generation libraries, and find a way of approaching this as a computational solution I can approach and program myself.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ As for all procedural generation questions, it would be good to include examples on how your track should look like. Is it a closed loop racing track? Some city driving track? Tracks with forks? \$\endgroup\$ Commented Apr 29, 2024 at 12:09

1 Answer 1

0
\$\begingroup\$

For quite a while, Unity provides a really neat tool for defining curved paths like race tracks in form of an optional package: Splines.

A spline is a bezier path. Which means it is defined by several "knot" points. Those "knots" then get connected by a curved path. Optional "tangent" points can be used to tweak the curves that connect the knots.

So a splines allow you to define a race track using relatively little data. Then you just need to use that spline to turn it into a visible and playable race track. This requires some development. But there are lots of examples online for how to use splines to generate actual game objects.

Once you have a system that allows you to create a race track by manipulating a spline in your scene, you can create an algorithm that generates knots and tangents randomly, and thus can generate more or less plausible looking race tracks. Tweaking that algorithm to create race tracks that are actually interesting to race on would then be the fun part of the assignment.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.