Skip to content

Camera Tracking

Jonoym edited this page Aug 22, 2021 · 1 revision

Camera Tracking

The view of the game will be centred around the main character to allow the player to follow them around the map. This feature will allow the map to be more interesting with the layout design as well as hiding the entire layout from the player while they are traversing it. Tracking the character allows for a closer view on the main character while they are attacking enemies and using abilities instead of a very zoomed out alternative displaying the entire map.

Dynamically changing the zoom of the camera based on room sizes and other in game factors has been considered.

Implementation

To track the main character, the entity of the character needs to be stored within the camera component to allow the character's position, relative to the map, to be used to set the camera position. Whenever the camera position would update, it would be based on position of the character but this felt stiff and would often cause stuttering when the player would sprint and use dashes.

To fix this issue, the average of the last 50 positions was calculated and used as the camera position. This allows for the camera to quickly catch up to the player after using a dash while not following the player at the same speed, causing stuttering. The effect that this has allows for very smooth camera transitions to where the player is moving yet feels responsive enough such that nothing is ever out of view.

Private Attributes

  • player: The entity of the player the camera is focused on.
  • lastPositions: An array of up to the last 50 Vector2.

Public Methods

  • update(): This method previously was tracking the position of the camera and not the character. Changes to this use the character's position to centre the camera.
  • setPlayer(Entity player): This method is used to store the instance of the player the camera will track.

Private Methods

  • calculatePositions: This method calculates the average of the last positions of the camera and returns them in the form of a Vector2.

Table of Contents

Home

Design Document

Design Document

Design Document

Game Engine

Getting Started

Entities and Components

Item Drops from Entities

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Map Generation

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally