Search Unity

Idea for Checkpoints/reset/AI navigation/position?

Discussion in 'Scripting' started by kai_226, Sep 17, 2017.

  1. kai_226


    Jul 6, 2017
    Hey guys, I am currently working on a racing game and am thinking about the following system on a race track:
    A series of triggers with increasing numbers either in their name or in a script attached. This would help me to achieve following goals:
    - Use the position and numbering of triggers to navigate AI cars [like a path]
    - Calculate the position of each car depending on the current number of passed colliders
    - If the car falls off the track, I can use the last known trigger number - 5 to respawn the car

    Those are all convex plane colliders set up as triggers. Now my first question: There is a maximum of 7 cars on the track which would have trigger checks throughout the whole time. Is this a good approach?

    And the more difficult question: This system works fine for single way racetracks. But my tracks will have branches and maybe even branches inside branches. I think I can find a way to achieve AI navigation and respawning, but how would I reliably calculate the current position?

    I'm thankful for every idea you guys have :)
  2. Xepherys


    Sep 9, 2012
    Are you using Unity AI (NavMesh + Agent)? If so, split branches would be easy enough. At a given checkpoint, let's say there was a fork in the road ahead. You could set the next point randomly and it would follow the navMesh down whichever branch you had. Depending on speed and such, you could probably have a trigger region before each "checkpoint" that told the agent what it's next move point is, so it would never need to slow down as it approached (it would always have a future nav point). Or they could all be pre-calculated into an array from the start (each car already "knows" it's going this route or that).