Time for action – letting the player move
1. Add the following fields to the declarations area of the
CubeChaserGame
class:float moveScale = 1.5f; float rotateScale = MathHelper.PiOver2;
2. Add the following to the
Update()
method of theCubeChaserGame
class:float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; KeyboardState keyState = Keyboard.GetState(); float moveAmount = 0; if (keyState.IsKeyDown(Keys.Right)) { camera.Rotation = MathHelper.WrapAngle( camera.Rotation - (rotateScale * elapsed)); } if (keyState.IsKeyDown(Keys.Left)) { camera.Rotation = MathHelper.WrapAngle( camera.Rotation + (rotateScale * elapsed)); } if (keyState.IsKeyDown(Keys.Up)) { //camera.MoveForward(moveScale * elapsed); moveAmount = moveScale * elapsed; } if (keyState.IsKeyDown(Keys.Down)) { //camera.MoveForward(-moveScale * elapsed); moveAmount = -moveScale * elapsed; } if (moveAmount != 0) { Vector3 newLocation = camera.PreviewMove(moveAmount...