You do not tell the car where to go. In any case, this is due to its speed. If you look ahead (where there will now be several timestamps, and is there still a road?), You can see if you need to adjust the speed.
And the road is not an array; this is a matrix or bitmap. You cannot go so fast in the corner, or you are flying off the road.
It is always helpful to clearly articulate goals and frameworks first. In this case, you will think about the scale of the simulation (the physics involved) and the complexity of the car's movements (collisions, following bending roads, etc.).
I find that if you can clearly articulate your concept in plain English (or in my case in Dutch), writing code becomes much easier, almost trivially sometimes.
EDIT
For clarity, when I talk about speed, I'm talking about a vector that has both a magnitude (10MPH) and a direction. Your vectors will have 2 elements, x and y, if you also don't want planes, or want to model hills, etc. (You do not want the hills to force you to take gravity into account as well :) where az position and speed are used.
source share