I'm attempting to make a simple 2D car game from scratch, but I can't figure out the collision detection between a vehicle and a road. The vehicle should also rotate appropriately to its position on the road, as following (the vehicle is a rectangle and the road is a curve.):
As you can see, the vehicle collides with the road (but before it's being drawn, so that a user doesn't see that collision). Once the intersection is detected, the vehicle needs to be pushed away and rotated appropriately, as it's driving upwards:
The problem is the vehicle may have any rotation (assuming it won't be so fast to go through the road, missing the collision detection), as well as the road's curve may be directed towards any axis, making the algorithm hard to cover any possible situation.
Have you any idea how to achieve that?