I am working on 2d racing manager game. I am facing a problem on simulate racing. I create the race track with a racing line which all car will follow it. For large curve, the car moving look smooth, but for small curve, the moving is not nature, it move too fast. How can I manage the speed when the car enter curve? thank you
edit: I ignore physic in my game, there is no slide or drift
For every point along the racing track there is an absolute maximum speed; where exceeding the speed will cause the car to slide or roll. This maximum speed is determine by many things - the radius at that point in the racing line, how much grip the car has (how good tires are, how much down-force the car has from spoilers, track surface), how much mass the car has, where the car's center of mass is. If you want extremely realistic physics it'll be extremely complicated; but you get "good enough" results with a very simple code.
Once you've determined the absolute max. speed at each point on the racing line (for each type of car); you need to "smear it backwards" taking into account how good the car's brakes are. To understand what I mean, assume you have a long straight piece of track followed by a very tight (90 degree) right turn; where the car has "infinite" max. speed on the straight and 50 Km/h max. speed at the slowest point on the turn. To ensure the car can slow down in time you might end up with 55 Km/h a meter before the turn, 60 Km/h at 2 meters before the turn, etc. This gives you something like
practical_max_speed = min(absolute_max_speed, max_speed_to_slow_down_in_time);.Note that you don't actually need to determine the practical max. speed at every point on the racing line. It's enough to select some points (e.g. maybe every meter of track) and interpolate between them (e.g. if a car is 40% of the way between a previous "50 Km/h" point and a future "80 Km/h" point you can say that the car's max. speed is "0.4 * 50 + (1 - 0.4)*80 = 68 Km/h".
Of course all of this can be pre-determined (for each track, for each type of car) before the race starts (and you could just cheat and assign "max. speed/s" at various points by hand if all your cars are the same).
The problem is that sometimes cars go off of the racing line (e.g. to overtake, because they had mechanical failures, because they're making a pit stop, because there's a hazard on the track, because they just left the starting grid, etc). For this you can dynamically generate a new path and do all the calculations needed to determine practical max. speed along the new path. Alternatively (if you don't care so much about perfect physics and just want a game that's fun) you can cheat by having pre-defined alternative paths (e.g. maybe 3 specific corners where cars can over-take), or cheat by assuming the actual max. speed is the "practical max speed on racing line - distance from racing line * something", or cheat even more (assume cars are on the racing line when they aren't).