Projected focus and camera attractors

A locked-on camera is not a terrible thing, but a better camera shows more of what the player needs to see. In our game, the player is more likely to be interested in what lies ahead in the direction they are moving. A camera that looks ahead in the direction of movement is sometimes called a projected focus camera. We can look at the velocity at which our ship is currently moving, and offset our camera accordingly.

Another camera technique that we will employ is called camera attractors. Sometimes in games, there are objects of interest that can be used to pull/attract the focus of the camera. These create an attractive force that will pullĀ our camera in that direction. One attractive force for our camera is the enemy ship. Another attractive force is projectiles. The enemy ship represents potential action, and projectiles represent a potential threat to our player. In this section, we will combine a projected focus with camera attractors to improve our camera positioning.

The last thing I would like to add is an arrow that points the way toward the enemy spaceship. Because the play area is now larger than the canvas, we need a hint to help us find the enemy. Without this, we may find ourselves wandering around aimlessly, which is not very fun. Another way we could have done this is with a mini-map, but, because there is only a single enemy, I felt an arrow would be easier to implement. Let's walk through the code we need to add to improve our camera and add our locating arrow.