Getting Started
使用 KCC 預製變體創建角色
創建自訂角色最簡單的方法是從預設的KCC
預製物件創建一個變體:
- 右鍵點擊
KCC
預製物件(位於Assets/Photon/QuantumAddons/KCC/AssetDB/Entities
)。 - 選擇
Create > Prefab Variant
。

- 新增自己的視覺效果和自訂元件。
- 角色已準備就緒。繼續進行移動角色
從頭開始創建角色
- 創建一個新的玩家預製物件。

- 在根遊戲物件上新增
Quantum Entity View
及Q Prototype KCC
。可選新增Capsule Collider
。

- 配置遊戲物件
- 設定遊戲物件的圖層(可選)。
- 在
Quantum Entity View
中將Bind Behaviour
設為Verified
。 - 在
Quantum Entity Prototype
中將Transform
設為3D
。 - 啟用
PhysicsCollider3D
並將先前創建的Capsule Collider
連結到SourceCollider
(可選)。 - 在
Q Prototype KCC
中設定參考至KCC Settings
資產。
- 角色已準備就緒。繼續進行移動角色
配置 KCC 行為
KCC 附加元件包含一些預先配置的資產。
- 選擇
Assets/Photon/QuantumAddons/KCC/AssetDB/KCCSettings.asset
以配置預設值(半徑、高度、碰撞層遮罩)。這些值應與上方創建的膠囊碰撞器中的值匹配。

- 如果您正在創建新的
KCC Settings
資產,請連結 KCC 處理器。這些處理器負責實際的移動邏輯,更多資訊可在處理器章節中找到。預設處理器位於Assets/Photon/QuantumAddons/KCC/AssetDB/Processors
。
移動角色
移動過程在KCC
元件更新中處理。這由KCC System
管理,因此必須將其新增到您的Systems Config
中。

以下程式碼範例設定角色的視角旋轉和輸入方向給KCC
,隨後由EnvironmentProcessor
(或您自己的處理器)處理。
C#
public unsafe class PlayerSystem : SystemMainThreadFilter<PlayerSystem.Filter>
{
public struct Filter
{
public EntityRef Entity;
public Player* Player;
public KCC* KCC;
}
public override void Update(Frame frame, ref Filter filter)
{
Player* player = filter.Player;
if (player->PlayerRef.IsValid == false)
return;
KCC* kcc = filter.KCC;
Input* input = frame.GetPlayerInput(player->PlayerRef);
kcc->AddLookRotation(input->LookRotationDelta.X, input->LookRotationDelta.Y);
kcc->SetInputDirection(kcc->Data.TransformRotation * input->MoveDirection.XOY);
if (input->Jump.WasPressed == true && kcc->IsGrounded == true)
{
kcc->Jump(FPVector3.Up * player->JumpForce);
}
}
}
也可以完全跳過處理器功能,直接使用kcc->SetKinematicVelocity();
設定速度。
更多移動程式碼範例可在範例專案中找到。
Back to top