Skip to content

Player Camera

Maxsever12 edited this page Sep 2, 2026 · 2 revisions

Player following camera

In order to facilitate a larger map, the camera was changed from being fixed to a tracking and following the player. Additionally the cameras has its own speed, allowing the camera to smoothly follow the player for a better gameplay experience. On top of this the camera will not cross the "Wall" boundaries of a room.

The camera also works off any entity as the implementation uses the entities position, future additions can use this to follow any other entity.

Usage

The room entity should add FollowingCameraComponent to their components. Additionally for the component to work the camera, and either a target entity, or a goal vector has to be added to the component. If the camera is not given to the component it will not do anything.

player.getComponent(FollowingCameraComponent.class).setCamera(render.getCamera);
player.getComponent(FollowingCameraComponent.class).setTarget(player);

To temporarily stop the camera from following the player, remove the target

player.getComponent(FollowingCameraComponent.class).removeTarget();

// camera is no longer following the player
// ...


player.getComponent(FollowingCameraComponent.class).setTarget(player);

// camera resumes following the player
// ...

Implementation details

Every update, the component takes the goal position (if there is a target entity, that entities position is its goal), calculates how much to move based on its speed, then sets the camera's (provided by the renderer) position which the render updates for the user to see on screen.

UML diagram:

...

Table of Contents

Home

Test Plan

Team 2

Features

Components
Player
Items and Inventory
Enemies
Interactable NPCs
Cutscenes and Dialogue
Music
Bosses
Rooms
Weapons
Abilities & Spells
Game Screens and Areas
Dungeons

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally