This document is about: FUSION 2
SWITCH TO

Architecture

This section describes relationship of the KCC to other components and communication flow.


Collider

  • KCC collider is created at runtime as a child game object.
  • Layer of the collider game object is controlled via KCCSettings.ColliderLayer and is synchronized over network.

Rigidbody

  • Rigidbody component is required by KCC and used for immediate position synchronization to the physics engine.
  • Is Kinematic flag must be enabled (enforced at spawn).

Transform

  • Transform component is used as write-only.
  • Position and rotation is read only once during spawn.

Following diagram shows how KCC works from high-level perspective:

KCC architecture
High-level KCC architecture.

Gameplay Scripts

  • User scripts which command KCC, representing “what to do” (move with a given direction, look at position, ignore a specific collider, do a jump, activate crouch, …).
  • Read information from the Data Layer (for example Is Grounded, Real Velocity, …).
  • Call Public API (KCC.SetInputDirection(), KCC.SetLookRotation(), KCC.Jump()).
  • Can interoperate with Interaction Scripts.
  • For example Player class which translates input (mouse delta) to KCC actions (KCC.SetLookRotation()).

Interaction Scripts

  • User scripts (implementing IKCCProcessor), representing “how to move” (projecting input direction while grounded, 50% slower speed while crouching, calculating desired velocity).
  • The logic is injected indirectly during Core Loop execution.
  • Write directly to the Data Layer or call Public API.
  • Can interoperate with Gameplay Scripts.
  • Can implement custom logic like any other NetworkBehaviour.
  • For example DashProcessor class which force override KCC move velocity for 5 seconds upon activation.

Public API

  • Provides set of commands which are immediately executed or transformed internally to be compatible with KCC execution flow, its features and current state (executing another set of commands, writing to Data Layer, safety checks).
  • Abstracts complexity away from user.
  • For example KCC.SetRadius() which sets Radius property in KCCSettings and immediately propagate the values to collider.

Core Loop

  • Handles base functionality like physics query, collision filtering, depenetration, networking, tracking colliders, step detection, ground snapping, networking, …
  • Reads/writes from/to Data Layer.
  • Executes stages to control movement via dependency injection (Interaction Scripts).

Following diagram shows a simplified application of above on a specific case:

KCC execution flow example
KCC execution flow example.

Player represents Gameplay Scripts. Environment Processor and Teleport Processor represent Interaction Scripts. Execution follows this order:

  1. FixedUpdateNetwork() is called on Player
  2. The Player script calls KCC.SetInputDirection() with custom vector based on input from keyboard or joystick
  3. KCC writes desired input direction into KCCData.InputDirection (Data Layer)
  4. FixedUpdateNetwork() is called on KCC
  5. KCC executes series of commands up to a point where data for movement should be calculated by Interaction Scripts (KCC Processors)
  6. KCC executes PrepareData stage on all processors that support this stage (in this case Environment Processor)
  7. The Environment Processor internally executes other set of stages which combine input direction and other properties and calculate KCCData.DynamicVelocity and KCCData.KinematicVelocity as a result
  8. All stages are executed at this point, KCC proceeds to actual move logic
  9. KCC combines all calculated velocities and external delta into position delta candidate
  10. KCC moves its collider by delta calculated in previous step, depenetrates overlapping colliders and refreshes internal list of collisions
  11. KCC invokes OnEnter()/OnExit() callbacks on newly entered/leaved colliders (in this case Teleport Processor => OnEnter())
  12. The Teleport Processor calls KCC.SetPosition() with target position
  13. The KCC.SetPosition() immediately teleports the KCC to a given position and sets the KCCData.HasTeleported flag to stop further execution (we don’t want to continue in movement after teleport)
  14. KCC resumes core loop after executing all callbacks
  15. KCC checks KCCData.HasTeleported flag for early exit (it is set to true in this case)
  16. KCC finishes execution of current update (skipping remaining position delta)

As you may have guessed, the movement can be designed by using many different processors, each contributing/injecting its own logic. More info can be found in Interactions section.

Back to top