大多數遊戲允許玩家使用自己的 Roblox 虛擬形象,雖然有些遊戲實施了像 UGC Homestore 模板一樣的遊戲內自訂系統。其他遊戲則對玩家虛擬形象進行有限的 修改,例如頭盔、翅膀或與遊戲類型匹配的配件。
要創建一個獨特的遊戲以改變用戶的外觀,您可以通過 虛擬形象設置 或 手動修改外觀 來自定義默認角色屬性。
全球虛擬形象設置
Studio 的 檔案 ⟩ 虛擬形象設置 允許您快速設置遊戲中多個全局玩家角色屬性。這些設置適用於所有加入您遊戲的玩家角色模型。要修改特定角色,例如非玩家角色模型,請參見 手動修改外觀。
在此窗口中,您可以設置各種預設選項,包括衣物、配件、身體部位、碰撞行為、動作等。在編輯這些設置時,應用設置的預覽將顯示在工作區中。
更多資訊,請參見 虛擬形象設置。
手動修改外觀
角色模型包含一個 Humanoid 對象,賦予模型特殊特性,例如行走、跳躍、裝備物品和與環境互動。
您可以通過更新 HumanoidDescription 程式化地修改 Humanoid。這包括您遊戲中的玩家角色模型或非玩家角色模型。
您可以使用 HumanoidDescription 在遊戲中調整以下角色屬性:
| 角色屬性 | 描述 |
|---|---|
| 比例 | 物理特徵的數字值 height、width、head、body type 和 proportion。這不會影響 R6 體型。 |
| 配件 | 角色裝備的 accessories 資產 ID。 |
| 經典服裝 | 可以應用於角色的 Shirt、Pants 和 ShirtGraphic 圖像材質的資產 ID。 |
| 身體部位 | 角色的 Face、Head、Torso、RightArm、LeftArm、RightLeg 和 LeftLeg 部分的資產 ID。 |
| 身體顏色 | 角色各個部分的 BodyColors。 |
| 動畫 | 可以在角色上使用的 Animations 的資產 ID。 |
使用 HumanoidDescription 自訂角色的步驟如下:
創建 HumanoidDescription
您可以直接在 資源管理器 層級中或在 Script 中創建新的 HumanoidDescription 實例,代碼如下:
创建新 HumanoidDescription 实例local humanoidDescription = Instance.new("HumanoidDescription")
在大多數情況下,您應該引用現有的 HumanoidDescription ,而不是使用默認的新 HumanoidDescription,這樣可以引用現有的玩家角色、虛擬形象裝扮或用戶 ID。
根據玩家角色
使用以下程式碼範例根據玩家角色的當前屬性創建新的 HumanoidDescription:
從玩家角色生成 HumanoidDescriptionlocal humanoid = player.Character and player.Character:FindFirstChildWhichIsA("Humanoid")local humanoidDescription = Instance.new("HumanoidDescription")if humanoid thenhumanoidDescription = humanoid:GetAppliedDescription()end
根據現有的服裝
使用以下範例程式碼來從服裝 ID 創建 HumanoidDescription,使用 Players.GetHumanoidDescriptionFromOutfitID:
從服裝 ID 生成 HumanoidDescriptionlocal Players = game:GetService("Players")local outfitId = 480059254local humanoidDescriptionFromOutfit = Players:GetHumanoidDescriptionFromOutfitId(outfitId)
根據特定用戶
使用以下範例程式碼來從用戶 ID 創建 HumanoidDescription,使用 Players:GetHumanoidDescriptionFromUserId():
從用戶 ID 生成 HumanoidDescriptionlocal Players = game:GetService("Players")local userId = 491243243local humanoidDescriptionFromUser = Players:GetHumanoidDescriptionFromUserId(userId)
修改 HumanoidDescription
要自訂 HumanoidDescription 屬性,請直接在 HumanoidDescription 上設置它們,或在將 HumanoidDescription 應用到角色之前使用指定方法。
以下程式碼範例提供了設定不同類型的 HumanoidDescription 屬性的示例:
更新各種 HumanoidDescription 屬性local humanoidDescription = Instance.new("HumanoidDescription")humanoidDescription.HatAccessory = "2551510151,2535600138"humanoidDescription.BodyTypeScale = 0.1humanoidDescription.ClimbAnimation = 619521311humanoidDescription.Face = 86487700humanoidDescription.GraphicTShirt = 1711661humanoidDescription.HeadColor = Color3.new(0, 1, 0)
設置多個配件
對於層疊或批量的配件更改,您可以使用 HumanoidDescription:SetAccessories() 來進行配件相關的更新。以下程式碼範例將層疊的毛衣和夾克按順序添加到 HumanoidDescription 中:
一次性更改多個配件local humanoidDescription = Instance.new("HumanoidDescription")local accessoryTable = {{Order = 1,AssetId = 6984769289,AccessoryType = Enum.AccessoryType.Sweater},{Order = 2,AssetId = 6984767443,AccessoryType = Enum.AccessoryType.Jacket}}humanoidDescription:SetAccessories(accessoryTable, false)
應用 HumanoidDescription
通過 Humanoid:ApplyDescription() 或 Humanoid.LoadCharacterWithHumanoidDescription 將 HumanoidDescription 應用到您的遊戲中的特定 Humanoid 角色上。
在單個角色上
ApplyDescription() 可以針對任何 Humanoid。使用以下程式碼為玩家角色添加一副新的墨鏡和新的軀幹:
更新特定玩家角色的 HumanoidDescriptionlocal humanoid = player.Character and player.Character:FindFirstChildWhichIsA("Humanoid")if humanoid thenlocal descriptionClone = humanoid:GetAppliedDescription()descriptionClone.Torso = 86500008-- 多個面部配件資產可在用逗號分隔的字符串中添加descriptionClone.FaceAccessory = descriptionClone.FaceAccessory .. ",2535420239"-- 將修改的 "descriptionClone" 應用到 humanoidhumanoid:ApplyDescription(descriptionClone)end
在所有玩家角色上
使用以下範例程式碼將 HumanoidDescription 應用到遊戲中所有當前玩家:
更新所有當前玩家角色的 HumanoidDescriptionlocal Players = game:GetService("Players")for _, player in Players:GetPlayers() dolocal humanoid = player.Character and player.Character:FindFirstChildWhichIsA("Humanoid")if humanoid then-- 創建 HumanoidDescriptionlocal humanoidDescription = Instance.new("HumanoidDescription")humanoidDescription.HatAccessory = "2551510151,2535600138"humanoidDescription.BodyTypeScale = 0.1humanoidDescription.ClimbAnimation = 619521311humanoidDescription.Face = 86487700humanoidDescription.GraphicTShirt = 1711661humanoidDescription.HeadColor = Color3.new(0, 1, 0)humanoid:ApplyDescription(humanoidDescription)endend
在所有生成的角色上
使用以下範例程式碼為所有生成的玩家角色設置特定的 HumanoidDescription:
更新所有生成角色的 HumanoidDescription
local Players = game:GetService("Players")
-- 停止自動生成以便在 "PlayerAdded" 回調中進行處理
Players.CharacterAutoLoads = false
local function onPlayerAdded(player)
-- 創建 HumanoidDescription
local humanoidDescription = Instance.new("HumanoidDescription")
humanoidDescription.HatAccessory = "2551510151,2535600138"
humanoidDescription.BodyTypeScale = 0.1
humanoidDescription.ClimbAnimation = 619521311
humanoidDescription.Face = 86487700
humanoidDescription.GraphicTShirt = 1711661
humanoidDescription.HeadColor = Color3.new(0, 1, 0)
-- 使用 HumanoidDescription 生成角色
player:LoadCharacterWithHumanoidDescription(humanoidDescription)
end
-- 將 "PlayerAdded" 事件連接到 "onPlayerAdded()" 函數
Players.PlayerAdded:Connect(onPlayerAdded)
如果 HumanoidDescription 實例是在 資源管理器 中創建並附加到工作區,則在 Script 中使用以下範例程式碼以訪問工作區實例:
local Players = game:GetService("Players")
-- 停止自動生成以便在 "PlayerAdded" 回調中進行處理
Players.CharacterAutoLoads = false
local function onPlayerAdded(player)
-- 使用 "workspace.StudioHumanoidDescription" 生成角色
player:LoadCharacterWithHumanoidDescription(workspace.StudioHumanoidDescription)
end
-- 將 "PlayerAdded" 事件連接到 "onPlayerAdded()" 函數
Players.PlayerAdded:Connect(onPlayerAdded)
非 R15 模型上的層疊服裝
有籠配件的層疊服裝使用 WrapTarget 和 WrapLayer 在目標 Model 上進行拉伸和包裹。層疊配件可以與標準的 R15 Roblox 角色 和非 R15 模型一起使用。
自訂的層疊服裝實現,例如使用獨特籠子 UV 地圖的模型,不能上傳和發布到市場。更多資訊,請參見 層疊服裝規範。
無論您是在 R15 角色上實施層疊配件,還是使用自訂的模型,請確保您的配件和身體部位包括以下內容:
- 目標模型,通常是身體,必須在要包裹的網格上具有 WrapTarget 組件。
- 層疊模型,通常是衣物或配件,必須在要包裹目標模型的網格上具有 WrapLayer 組件。
- 目標模型的外層籠,以及 層疊模型的內層和外層籠 必須具有匹配的 UV 地圖。
- 對應於目標籠的頂點應具有與層籠相同的 UV。
- 如果您的目標模型既是 R15 且包含 Humanoid,則此焊接將自動創建。