This document is about: QUANTUM 2
SWITCH TO

Prediction Area

Overview

The PredictionAreaSystem is responsible for updating the prediction area in Quantum based on the local player metadata provided by the PredictionAreaInfo. At runtime, the data is provided and updated by Unity in Register.cs which is a service added to the SimulationContextService list in SimulationContext.User.cs.

Prediction in Fast Paced Games

By default, the prediction area is set from Unity which provides:

  • a position in world space, usually the position local player; and,
  • a radius, usually representing the viewfield of the local player.

However, this is unsuitable for prediction in fast paced games where characters move extremely fast.

The Problem

If the local player is moving fast enough, they will be leaving the prediction area used for the next predicted simulation tick. This will result in the local player not being simulated at all in the next predicted frame. Since the movement in Unity relies on the latest predicted frame to animate the actor entity. Until the prediction area catches up and includes the local player again, the movement will stutter as it has to wait until the next verified frame to be simulated.

The Solution

To ensure the prediction area always includes the local player, the local player's EntityRef is tied to it by the FPS Template API from Unity. This allows Quantum to adjust the center of the prediction area at the start of each predicted frame thus making sure the the local player entity is simulated as part of the predicted frame.

The FPS Template thus proceeds with the following steps to implement this solution:

  1. The quantum simulation tick is executed with player position as the center of the prediction area.
  2. When the tick ends, the execution is handed back to Unity so it can update itself (including the actor entity's movement animation).
  3. Unity updates the local player's current position and additing interpolation to it.
  4. The PredictionAreaInfo in the FrameContextUser is updated with that new position and the EntityRef of the local player's actor entity.
  5. Quantum takes over again simulate the next predicted tick:
    • if the EntityRef provided in the PredictionAreaInfo is valid, the PredictionAreaSystem uses it to grab the entity's Transform3D and sets its position as the center for the prediction.
    • if the EntityRef is invalid or set EntityRef.None, it will use the position provided by Unity in PredictionAreaInfo. This scenario is commonly tied to the actor entity just having died / despawned.
Back to top