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:
- In case of a humanoid entity, body rotation is usually locked to allow only Y axis rotations.
- 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 specificTransform3D
to anEntityComponentLook
.Version
: used to synchronize overrides and to prevent accidental overwritesIgnore Input
: if set, the component will completely ignoreLookDesires
Freeze X
: if set, entityTransform3D
rotation around X axis is locked to a specific value, can be overriddenFreeze Y
: if set, entityTransform3D
rotation around Y axis is locked to a specific value, can be overriddenFreeze Z
: if set, entityTransform3D
rotation around Z axis is locked to a specific value, can be overriddenLook Position
: world space look positionLook Rotation
: unconstrained look rotationFreeze Euler Rotation
: used to overwrite entityTransform3D
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:
- The local rotation in Unity is always updated at the render speed and is independent of the Quantum simulation.
- An entity controlled by a local player always reads its rotation value from the locally stored rotation. This enables smooth rotation without interpolation.
- 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 theLook
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. - 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 theVersion
value). Next time the input is polled, the client will provide a new input rotation with the correctVersion
.
This execution flow is presented in the diagram below.
Back to top