Rotate player automatically in an infinite runner to follow a winding road C#

So I have a question here that I do not think has been previously addressed (well at least I can’t find anything that can help).

So I am trying to change my level design around at the moment in an infinite runner style game where the player is constantly moving forwards (in a straight line with camera position fixed and centered).

However what I need to achieve is to have the player and camera rotate in parallel with the road automatically when twists and turns are detected so that the player doesn’t eventually get stuck running against one of the walls on the side of the road.

So if my road bends to the left several times the player doesn’t continue to go forward but instead remains parallel (still facing forward with the road ahead. I have not attempted to code this yet as I just wanted to know the best way to approach this before I do as I can think of several different approaches but I do not know if any of them are the right solution since I have not ever tackled this before or anything similar.

Things worth mentioning:

  • My level design is spawned as tiles randomly during play so is different each time it is played.

  • My player can move left and right to avoid obstacles during game, but not forwards or backwards.

  • Speed gradually increases until it reaches maximum speed.

Not sure if I have explained this well enough but if anybody could provide any pointers at all, that would be really helpful at this stage.

Thanks in advance,


Did you find a solution? I am stuck on this too!