Sprite with specific time limit.

I have 4 cars. All cars stored in an array. Each car has 15 seconds time limit.
If any car:

  • is crashed
  • or the reached the destination
  • or the time
    the next car takes the turn.
  this.cars[i].setMovingTime = () => {
        this.time.addEvent({
          delay: this.TOTAL_TIME,
          callback: () => {
            this.cars[i].isMoving = false;
          },
        });
      };

In update funciton once the time is up. I set the current car to next car. But It instantly moves the last car.

Could you please help how to solve this problem ?

:wave:

const car = this.cars[i];

this.time.addEvent({
  delay: this.TOTAL_TIME,
  callback: () => {
    car.isMoving = false;
  },
});