This document is about: FUSION 2
SWITCH TO

Creating Character

KCC prefab variant

The easiest way to create custom character is to create a prefab variant from default KCC prefab:

  1. Right click on KCC prefab (in Assets/Photon/FusionAddons/KCC/Prefabs).
  2. Select Create > Prefab Variant.
create prefab variant
Create KCC prefab variant
  1. Configure KCC settings (radius, height, collision mask, ...) if needed. More details in KCC Settings section.
configure prefab variant
Configure KCC prefab variant
  1. Replace capsule visual with your own visual, add custom components.
  2. The character is ready for use. Continue with Moving the character

Creating character from scratch

  1. Create a new player prefab.
create player prefab
Create player prefab
  1. Add NetworkObject, Rigidbody and KCC components to the root game object.
add components
Add components to player prefab
  1. Enable Is Kinematic option on Rigidbody component.
  2. Configure KCC settings (radius, height, collision mask, ...) if needed. More details in KCC Settings section.
configure player prefab
Configure player prefab
  1. Link default processors in KCC settings. They are located in Assets/Photon/FusionAddons/KCC/Prefabs.
link default processors
Link processors
  1. Add visual and other components.
  2. The character is ready for use. Continue with Moving the character

Moving the character

Following example code sets character look rotation and input direction for KCC which is later processed by EnvironmentProcessor.

C#

public override void FixedUpdateNetwork()
{
    if (Runner.TryGetInputForPlayer(Object.InputAuthority, out BasicInput input) == true)
    {
        // Apply look rotation delta. This propagates to Transform component immediately.
        KCC.AddLookRotation(input.LookRotationDelta);

        // Set world space input direction. This value is processed later when KCC executes its FixedUpdateNetwork().
        // By default the value is processed by EnvironmentProcessor - which defines base character speed, handles acceleration/friction, gravity and many other features.
        Vector3 inputDirection = KCC.Data.TransformRotation * new Vector3(input.MoveDirection.x, 0.0f, input.MoveDirection.y);
        KCC.SetInputDirection(inputDirection);
    }
}

It is also possible to skip processors completely and just set the velocity using KCC.SetKinematicVelocity();.

More movement code examples can be found in Sample Project.

Back to top