Search Unity

Racing Checkpoints and Lap Completions.

Discussion in 'Scripting' started by cl9-2, Oct 1, 2014.

  1. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
    Hi,

    I'm working on a racing game checkpoint system where each checkpoint is represented by an auto-generated box collider trigger that has the width of the road at that point. The tracks have no barriers and it's possible to skip certain checkpoints, so I am keeping track of each checkpoint with a boolean array. Determining whether each car has completed a lap seems to require looping through the entire array each time it passes a checkpoint, which I'm concerned might be expensive for the CPU already busy with physics and AI. Is there a faster way to encode checkpoint information and determine if a lap is complete?

    Thanks!
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Every checkpoint you need to check if the previous one has been completed. The only thing you need to do is store the previous checkpoint in an int. Every checkpoint you check if the previous one equals this one minus 1.
     
    cl9-2 likes this.
  3. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    490
    Make an array the length of cars. Then just set the checkpoint state for each car in it (for example, checkpoint 4)

    Btw. Virtua Racing. I approve (Y)
     
    cl9-2 likes this.
  4. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
    Thanks, this works.