Skip to content

FOV Component

yuvrajsingh001 edited this page Sep 12, 2023 · 6 revisions

FOV Component Documentation

Overview

The FOV (Field of View) component is a critical part of the game engine, responsible for detecting enemies within a certain radius of a turret. This documentation provides an in-depth explanation of the FOV component, its purpose, and how to use it effectively in your game.

Table of Contents

Introduction

The FOV component is used to determine which enemies are within the field of view of a turret. It accomplishes this by checking the distance between the turret and potential enemy entities. When an enemy enters or exits the field of view, callback functions can be triggered to perform specific actions.

Usage

Creating an FOV Component

  1. Create an instance of the FOV component, specifying the radius and callback functions for entering and exiting the FOV.
FOVComponent fovComponent = new FOVComponent(radius, this::onEnterFOV, this::onExitFOV);
  1. Attach the FOV component to the turret entity.
turretEntity.addComponent(fovComponent);

Updating the FOV Component

fovComponent.update();
```### ## 
## Example
```java
// Create an FOV component with a radius of 5 units
FOVComponent fovComponent = new FOVComponent(5.0f, this::onEnterFOV, this::onExitFOV);

// Attach the FOV component to a turret entity
turretEntity.addComponent(fovComponent);

// Update the FOV component within the game loop
while (gameIsRunning) {
    fovComponent.update();
    // Other game logic here
}
Clone this wiki locally