This week I focused mainly on improving the camera. First, I added three options for the camera’s position, which can be cycled through while playing.
I also spent quite a bit of time trying to figure out how to prevent the player from going off the edge of the screen. Our first pass at the camera script set it to look directly at the player, but when racing quickly, this felt like running while staring at your shoes. So instead, I made the camera look at a point slightly down the track from the player. The problem with that solution was that if the look ahead value was too big, on sharp corners the player would go off the edge of the screen.
To solve this, I retrieved the player’s position in screen space to determine how close to the center of the screen they are. Then I used this value to interpolate between looking at the point down the track, and looking at the player.
The following image represents the player’s “off-centerness”, white being nearly off-screen, and black being fully centered. The higher this value (closer to white), the more the camera takes the player’s position into account.
That’s it for this week.