This document is about: QUANTUM 2
SWITCH TO

Look

Overview

The LookSystem controls an entity's Transform3D rotation and provides a way to store information about entity look orientation; these rules can differ from the ones applied to to body rotation. The LookSystem and Look component aims to solve two core issues:

  1. In case of a humanoid entity, body rotation is usually locked to allow only Y axis rotations.
  2. Versioning to enable and coordinate authoritative look direction behavior in the view (Unity) and the simulation (Quantum).

Component

The Look component allows to handle an agent's view direction independently from its body. This enables to override constrains set in the Transform3D as can be seen from the properties found in the Look component:

  • Look Offset: relative offset of head/eyes center from entity pivot (feet), this property is baked in Unity when linking a specific Transform3D to an EntityComponentLook.
  • Version: used to synchronize overrides and to prevent accidental overwrites
  • Ignore Input: if set, the component will completely ignore LookDesires
  • Freeze X: if set, entity Transform3D rotation around X axis is locked to a specific value, can be overridden
  • Freeze Y: if set, entity Transform3D rotation around Y axis is locked to a specific value, can be overridden
  • Freeze Z: if set, entity Transform3D rotation around Z axis is locked to a specific value, can be overridden
  • Look Position: world space look position
  • Look Rotation: unconstrained look rotation
  • Freeze Euler Rotation: used to overwrite entity Transform3D rotation around locked axis

Look Direction Concurrency

In a fast paced first person view game, it is crucial to have immediate and non-interpolated input response. This requires the client to update the local player's rotation authoritatively in Unity at render speed and send the absolute rotation when the input is polled by the simulation. However, it is just as important for the simulation to have a way to force override player rotation. To solve the cocurrency problem between View and Simulation, the Look component is equipped with a Version property.

The FPS Template thus handles the look direction as follows:

  1. The local rotation in Unity is always updated at the render speed and is independent of the Quantum simulation.
  2. An entity controlled by a local player always reads its rotation value from the locally stored rotation. This enables smooth rotation without interpolation.
  3. If the Quantum simulation needs to force set the rotation according to the game rules (e.g. spawning in a specific direction), it is required to increment the Version in the Look component; otherwise, the rotation can be overwritten by the cached values in Unity when polling the next input. This scenario is most likely to happen when the render speed is lower than simulation speed which means multiple predicted Quantum frames will have been simulated between Unity frames.
  4. If the Version gets invalidated, it will be detected by the client at the beginning of the next Unity frame. In this case, the client will reset its cached values to the ones provided by the simulation (including the Version value). Next time the input is polled, the client will provide a new input rotation with the correct Version.

This execution flow is presented in the diagram below.

look
Look.
Back to top