This document is about: FUSION 2
SWITCH TO

Creating Character

KCC預製件變體

建立自訂角色的最簡單的方式是從預設KCC預製件來建立一個預製件變體:

  1. 以右鍵按一下KCC預製件(在Assets/Photon/FusionAddons/KCC/Prefabs中)。
  2. 選擇Create > Prefab Variant
create prefab variant
建立KCC預製件變體
  1. 按需要設置KCC設定(半徑、高度、碰撞遮罩等等)。在KCC設定章節中有更多細節。
configure prefab variant
設置KCC預製件變體
  1. 以您自己的視覺效果來替換膠囊視覺效果,新增自訂元件。
  2. 角色已經準備好使用。繼續進行移動角色

從零開始建立角色

  1. 建立一個新的角色預製件。
create player prefab
建立玩家預製件
  1. 新增NetworkObjectRigidbodyKCC元件到根遊戲物件。
add components
新增元件到玩家預製件
  1. Rigidbody元件上啟用Is Kinematic選項。
  2. 按需要設置KCC設定(半徑、高度、碰撞遮罩等等)。在KCC設定章節中有更多細節。
configure player prefab
設置玩家預製件
  1. KCC設定中鏈接預設處理器。它們位於Assets/Photon/FusionAddons/KCC/Prefabs中。
link default processors
鏈接處理器
  1. 新增視覺效果及其他元件。
  2. 角色已經準備好使用。繼續進行移動角色

移動角色

以下示例程式碼針對KCC來設定角色查看旋轉及輸入指示,其在稍後由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);
    }
}

也可以完全略過處理器,而只使用KCC.SetKinematicVelocity();來設定速度。

可以在範例專案中找到更多移動程式碼示例。

Back to top