Introduction to Fields of View

Get a brief introduction on the field of view.

We'll cover the following

In the darkness ahead, the hero sees an orc. Hoping to sneak past, our hero skirts the room, but the orc turns to give chase. Sprinting down the hall with the orc hot on their heels, the hero turns into a side passage and hides. The hero was lucky this time; the orc broke off pursuit.

This scene requires that neither the hero nor the monsters are aware of each other’s position until they can see each other. Monsters still chase the player, but only when they can see their intended target. The player is able to maneuver to break the line of sight and escape from the monster. In previous chapters, entities are effectively omniscient, able to see the entire map at once. The new features require that entities know what they can see and are able to query the map to interact only with targets they have spotted.

Restricting entities’ view of the world adds several dimensions to the game:

  • The player is no longer certain of their exact location on the map and has less warning about what may lie around the next corner.
  • Restricted vision adds dramatic tension to the game — every corner might hide a terrible demise.
  • The game is more tactical, with the player having the option to hide and avoid combat and to engage at their own pace.

What will we learn?

In this chapter, we’ll give the adventurer and monsters a FieldOfView component and system that lists tiles visible from their current location. We’ll then limit map rendering to only show areas currently visible to the player. Next, we’ll replace the heat-seeking monster chase AI with one that begins the chase when the adventurer is visible and breaks off the chase if the adventurer escapes.

Finally, we’ll give the player a memory of the map that they have discovered and display the memorized map in gray. Along the way, we’ll learn about a new Rust collection—the HashSet.

Get hands-on with 1200+ tech skills courses.