Search Unity

Car Race Game - Results Calculation issue

Discussion in 'Scripting' started by Droove92, Apr 15, 2014.

  1. Droove92

    Droove92

    Joined:
    Jul 5, 2013
    Posts:
    23
    Hello everyone !
    I'm currently developing a car racing game.....but I'm stuck at this point.....
    If , by chance, the human player finishes the race a good time before the AI cars, then how to calculate their results??
    do we have to wait for them until they cross the finish line? (this will be boring......)

    BTW , I have an idea, i.e., to display an "please wait..." screen and perform the following operation :

    Code (csharp):
    1. Time.timeScale = 4;
    or maybe more (so that AI cars quickly cross the finish line). Then afterwards, reset the time scale.....
    Is this idea a good idea? will it affect the actual racetime ?

    Plz help me......


    Thanks in advance!!
     
    Last edited: Apr 15, 2014
  2. Droove92

    Droove92

    Joined:
    Jul 5, 2013
    Posts:
    23
    please?......
    anyone....??
     
  3. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    It would depend on how you game works.
     
  4. Droove92

    Droove92

    Joined:
    Jul 5, 2013
    Posts:
    23
    It is a normal car racing game, where you select a car, a racing track, no. of laps opponents.....then race around.....and when the race ends, results should be displayed immediately, just like in NFS, in which , no matter on which position you finish, the final results are displayed within few seconds (even when the enemy cars may not even have completed their last lap).

    I just want to know how does that work?
    How the results are displayed even when AI cars have not finished their course??
     
  5. msl_manni

    msl_manni

    Joined:
    Jul 5, 2011
    Posts:
    272
    Nobody likes to wait for AI to finish its race. You should calculate - FinishTime = (length of path left to finish + random(penality) + skill of driver + carDamage) * KPS;
     
  6. Droove92

    Droove92

    Joined:
    Jul 5, 2013
    Posts:
    23
    KPS??
    did you mean Km/s ?

    and BTW, i have very simple and basic scripts for AI.... the path / waypoint follow algorithm...so i don't have used any parameter such as skill of driver or amount of damage the car has received (affecting its handling) :)
     
    Last edited: Apr 25, 2014
  7. Droove92

    Droove92

    Joined:
    Jul 5, 2013
    Posts:
    23
    can anybody also help me calculate distance between 2 cars?...
    i know how to calculate distance between 2 objects, but you know, the distance is to be measured between 2 vehicles on a race track (rather in open 3d space, as it will result in shortest distance between them, neglecting the other objects boundaries, etc. ) ??
     
  8. msl_manni

    msl_manni

    Joined:
    Jul 5, 2011
    Posts:
    272
    As all your AI vehicles are using waypoints to follow the path, then its very easy to calculate distance on any kind of path. Just calculate a path of the waypoint that are in between the two cars and then you can calculate the distance between the two cars.

    TotalDistance = 0;
    TotalDistance += vector3.Distance(Car1.pos, waypoint6.pos);
    TotalDistance += vector3.Distance(waypoint6.pos, waypoint7.pos);
    TotalDistance += vector3.Distance(waypoint7.pos, waypoint8.pos);
    TotalDistance += vector3.Distance(waypoint8.pos, Car2.pos);

    Thats the final TotalDistance between the two cars.
     
  9. Droove92

    Droove92

    Joined:
    Jul 5, 2013
    Posts:
    23
    oh yes!....thanks for that... :)
    I didn't think of it....
     
  10. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    It's entirely up to you how your game works. Having said that try and follow some simple common sense rules:

    1) Don't make a human player wait for longer than a few seconds for AI.
    2) Don't make one human player wait for another human player for more than a minute. (Have a countdown clock)
    3) Give as much information to the human to show who is waiting for who.
    4) Let the humans abandon waiting somehow like a skip or quit button.

    If all players haven't finished the race when time is up either give them 0 points or calculate their distance to the finish or use some other method to determine the order.

    Actually if you get it right most of your AI cars should not be too far behind the humans! But just in case...

    I am making a racing car game too so I am having to think about all these things! Best thing to do is play a lot of car games and see what they do!


    Good luck! May the best car game win! :D
     
    Last edited: Apr 25, 2014