Time for action – moving the world
To move both the track and the skybox in relation to the camera, perform the following steps:
1. In the
Skybox
class, add a new property to allow us to set the rotation while maintaining a valid angle as follows:#region Properties public float Rotation { get { return rotation; } set { rotation = MathHelper.WrapAngle(value); } } #endregion
2. Inside the
if
statement in theUpdate()
method of theMarsRunnerPlayScreen
class, just before the rover is updated, update the variable that controls the track position and rotate the skybox as follows:if (playerPosition < 2880) { playerPosition += 15 * elapsed; skybox.Rotation += 0.1f * elapsed; }
3. Execute the game.
What just happened?
The way the track is drawn is based on the playerPosition
variable. Hence, updating this value causes the track to scroll slowly past the camera. Similarly, slowly rotating the skybox to match the speed that the track is moving gives the illusion that the player is...