キャラクターの作成
KCC プレハブバリアント
カスタムキャラクターを作成する最も簡単な方法は、デフォルトの KCC
プレハブからプレハブバリアントを作成することです。
KCC
プレハブを右クリックします (Assets/Photon/FusionAddons/KCC/Prefabs
内)。Create > Prefab Variant
を選択します。


ゼロからキャラクターを作成する
- 新しいプレイヤープレハブを作成します。

- ルートゲームオブジェクトに
NetworkObject
、Rigidbody
、KCC
コンポーネントを追加します。

Rigidbody
コンポーネントのIs Kinematic
オプションを有効にします。- 必要に応じて
KCC
の設定(半径、高さ、コリジョンマスクなど)を行います。詳細はKCC Settingsを参照してください。

- ビジュアルとその他のコンポーネントを追加します。
- キャラクターが使えるようになりました。キャラクターの移動で続行してください。

- ビジュアルとその他のコンポーネントを追加します。
- キャラクターが使えるようになりました。キャラクターの移動で続行してください。
キャラクターの移動
以下のコード例では、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