角色控制器

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

Class.ControllerManager 實例管理模擬動作控制,為其指定的 RootPart 。 以上於 ControllerPartSensors 的基礎上,可用於建立物理基礎角色控制器。

核心設定

ControllerManager 需要一個 BasePart 作為其根。移動力和零件感應將在此部分上。

  1. 選擇 PartMeshPart 並命名為 RootPart。

  2. 將零件組成 Model 實例以整體組織,並與其他零件一起。

  3. ControllerManager 實例添加到模型。如果 ControllerManager 不會在對象插入菜單中出現,請在 “顯示只有推薦對象” 在選單的 1>插入設定1> 中取消選擇。

    ControllerManager and RootPart inside model

感應器設定

Class.ControllerPartSensor 檢測零件,使用 Humanoid 檢測地板和梯子。

  1. ControllerPartSensor 作為 根部分 的兒級,並將其重命名為 地面感應器 以更容易識別其目的。然後,在 1> 屬性

    GroundSensor as child of RootPart
    GroundSensor properties
  2. 將另一個 ControllerPartSensor 作為 根部分 的兒級,並將其重命名為 攀爬感應器 。然後,在 1>屬性1> 視窗中,將其 4>

    ClimbSensor as child of RootPart
    ClimbSensor properties

控制器設定

GroundControllerClimbController 這樣的控制器實例告訴管理部分如何與世界互動,在 感應器設定 中與感應器配置的感應器互動。

  1. 在 Class.ControllerManager 的兒女中,插入 both a ClimbControllerControllerManager 作為 Class.ControllerManager 的兒女。

    GroundController and ClimbController as children of ControllerManager
  2. 選擇新的 GroundController 實例,然後在 屬性 窗口中設定其 GroundOffset 屬性為

    GroundController properties

鏈接參考

要完成核心設定,您需要將 ControllerManager 實例中的各種屬性鏈接到主要 Model 中的對象。

  1. 選擇 ControllerManager 實個體、實例。

    ControllerManager selected in Explorer window
  2. 屬性 窗口中,按一下以下各個屬性,然後,在 Explorer 窗口中,按一下相應的實例來完成鏈綁定。

    1. ActiveController 屬性鏈接到 GroundController 實個體、實例。
    2. 連接 RootPart 屬性到你命名的零件 RootPart
    3. ClimbSensor 屬性鏈接到 ClimbSensor 個體、實例。
    4. GroundSensor 屬性鏈接到 GroundSensor 個體、實例。
    ControllerManager properties linked to instances within overall model

測試

有了 感應器控制器 在空間置,以及有了 與參考相關,你就可以在 Studio 測試控制器。

  1. 使用 執行模式 ( F8 ) 來測試您的虛擬人偶角色,因為您不需要在此情況下插入您的虛擬人偶。

    Rapid playtest options in Test tab of Studio
  2. 根部分 應該在 GroundController.GroundOffset 值你在 添加控制器 中設置的上升到地面。它還應該旋轉來與 0> Class.ControllerManager.FacingDirection0> 向向量力對稱。

    Character levitating above ground at GroundOffset, facing in direction of FacingDirection vector
  3. 在執行階段時間改變 MovingDirection 和 Class.ControllerManager.FacingDirection|FacingDirection

    ControllerManager properties for moving and facing direction
    控制器管理器
    GroundController properties for acceleration, deceleration, and ground offset
    地面控制器

自訂感應器

Class.ControllerPartSensor.SensorMode 選項的 FloorLadder 執行正確的 1>Class.Humanoid1> 感應器代碼,讓您可以使用它們來檢測倒退兼容。 但您也可以自訂走路和

  1. ControllerPartSensor.UpdateTypeOnRead 切換到 手動

    • OnRead 會每次你閱讀它們時更新對應你的 SensorMode 。它本質上將感應器設置為只閱取模式,因此你寫在這些屬性上的任何內容都會被內部感應行為覆蓋。
    • 手動 關閉內部感應行為。輸出屬性是免費的,您可以隨便寫,但 SensorMode 不做任何事。
  2. 創建執行您自己感應論理的指令碼,並將輸出寫入您的感應器輸出屬性。通常您會使用空間查詢,例如 WorldRoot:Raycast()WorldRoot:Blockcast(),以返回 RaycastResult。您的指令碼可以然後取得結果屬性並將它們設置在

    注意,您需要管理查詢的執行頻率和更新感應器實個體、實例。

  3. Class.ControllerManager 將繼續使用它所分配的感應器,取得您傳送給它的資料。