0
\$\begingroup\$

I'm considering writing a very simple management style game with the theme being motorsport racing.

I've got a good idea how to do the 'management side', but the issue I'm having is how to visually render cars and move on a track (something a bit like):

enter image description here

The key points (keeping it simple):

  • the user won't control the vehicle directly, they are the 'manager' (think football manager) - they can decide on a strategy but cannot control the vehicle
  • the car should stay on track (visually) - they may 'crash' (along with other events) though
  • the speed it goes around the track is determined by vehicle performance
  • a car will be aware of other near-by cars around the track - for example, if they're about to be overtaken, they may actually do a slower lap as they are defending - they may collide, along with other events

My initial thoughts are there are two key design elements here, the track and the car.

The track:

  • a track is composed of many segments
  • each segment is stored in an array
  • a segment (I'm not entirely sure here) but one thing it might contain is a 2D array:

(From [this](https://gamedev.stackexchange.com/questions/149966/approaches-on-2d-top-view-racing-game-track-design) answer gave an approach of using multi-dimensional arrays)
_ _ _ _ _ _ _ _ _ _
| d d x x x d d d |
| d d r r r d d d |
| d d r r r d d d |
| d d r r r d d d |
| d d r r r d d d |
| d d r r r d d d |
| d d r r r d d d |
| d d e e e d d d |
| _ _ _ _ _ _ _ _ |

_ _ _ _ _ _ _ _ _ _
| d d x x x d d d |
| d d r r r d d d |
| d d d r r r d d |
| d d d d r r r e |
| d d d d r r r e |
| d d d d d d r e |
| d d d d d d d d |
| d d d d d d d d |
| _ _ _ _ _ _ _ _ |

Above is a straight and a 90 degree corner - x exit, e entry, r racetrack and d dirt. Maybe I could create a bunch of these and create a track.

Or maybe a simpler version where I define just an entry and exit:

_ _ _ _ _
| d e d |
| d r d |
| d e d |
| _ _ _ |

_ _ _ _ _
| d x d |
| d r e |
| d d d |
| _ _ _ |

The simplified version where I define an entry e and exit x. I can add additional points r and then construct a curve/straight-line based on the x, e and r coordinates?

My idea is that the vehicle will then move across each segment and I can calculate the time it takes to complete that segment. I can then add up all segments which will give me the lap time. With this approach, I can also check the previous/current/next segment to determine if there are other vehicles it needs to defend/attack against.

The car:

  • store all vehicles in an array
  • each vehicle will always be in a segment
  • speed it completes the segment is determined by its performance (and segment characteristics)
  • vehicle can 'see' if there are other vehicles in previous/current/next segment and decide whether to overtake/defend.

I think I could make this work, but I'd be really interested to know if there are better/simpler approach - bearing in mind it's mostly a visualization and the speed and events are determined by my program.

\$\endgroup\$
3
  • \$\begingroup\$ For the level of detail shown in your example image, it would probably suffice to use a spline instead of a tile-based approach. \$\endgroup\$
    – DMGregory
    Commented Aug 24, 2020 at 20:38
  • \$\begingroup\$ What engine are you using? \$\endgroup\$
    – Kevin
    Commented Aug 24, 2020 at 20:47
  • \$\begingroup\$ Not decided on engine yet @Kevin - but Unity is a possibility \$\endgroup\$
    – boywonder
    Commented Aug 24, 2020 at 20:51

1 Answer 1

0
\$\begingroup\$

Defining the track segments in some type of data structure may be necessary if you are using procedurally generated tracks that are built at runtime from assorted segments.

If you don't need the tracks to be procedurally generated, the solution is probably much simpler:

  1. Create each track as a single 2D image
  2. Define waypoints around the track that the vehicles will follow. These can be simple x-y pairs. If you're using an engine that has a visual editor, you might be able to place the waypoints in the visual editor (even if not, you'd probably want to build a simple visual interface for this purpose).
  3. Animate the cars from waypoint to waypoint. You may need to do a bit of path interpolation around turns to keep the motion smooth, but if this is a simple top-down representation then you might find that the extra smoothness from interpolation isn't necessary.
\$\endgroup\$
4
  • \$\begingroup\$ Nope the track doesn't need to be procedurally generated (it's all pre-defined) so this sounds like a significantly simpler approach. Since the track is composed of various waypoints, I assume I should be able to configure the speed the car moves from one waypoint to the next (so I'll be able to see a car slowing down in a corner, speeding up on straights as examples) \$\endgroup\$
    – boywonder
    Commented Aug 24, 2020 at 21:02
  • \$\begingroup\$ Yes, of course you can add supplementary data to the waypoints as needed for your purposes. If this answer is helpful or resolves your question, please don't forget to upvote or mark as the correct answer. \$\endgroup\$
    – Kevin
    Commented Aug 24, 2020 at 21:23
  • \$\begingroup\$ Thanks that's really helpful! \$\endgroup\$
    – boywonder
    Commented Aug 25, 2020 at 6:19
  • \$\begingroup\$ Great, glad to help! \$\endgroup\$
    – Kevin
    Commented Aug 25, 2020 at 16:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .