大多數體驗允許玩家使用自己的 Roblox 角色,雖然有些則實施類似於 UGC Homestore 模板的遊戲內自訂系統。其他體驗則對玩家角色做出有限的 修改,例如頭盔、翅膀或與類型相匹配的配飾。
要創造一種獨特的體驗以改變您的用戶外觀,您可以透過 角色設定 或 手動修改外觀 自訂預設角色屬性。
全局角色設定
Studio 的 File ⟩ Avatar Settings 允許您快速設置體驗中多個全球玩家角色屬性。這些設定對所有進入您體驗的玩家角色模型全局適用。要修改特定角色,如非玩家角色模型,請參見 手動修改外觀。
在此窗口中,您可以設置衣物、配飾、身體部位、碰撞行為、動畫等的多種預設。在編輯這些設定時,應用設定的預覽會在工作區顯示。
欲了解更多資訊,請參見 Avatar Settings。
手動修改外觀
角色模型包含一個 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
您可以直接在 Explorer 層級或在 Script 中使用以下代碼創建新的 HumanoidDescription 實例:
創建新的 HumanoidDescription 實例
local humanoidDescription = Instance.new("HumanoidDescription")
在大多數情況下,您應該通過引用現有的玩家角色、角色外觀或用戶 ID,使用現有的 HumanoidDescription,而不是使用默認的新 HumanoidDescription。
從玩家角色
使用以下代碼示例創建基於玩家角色當前屬性的新 HumanoidDescription:
從玩家角色生成 HumanoidDescription
local humanoid = player.Character and player.Character:FindFirstChildWhichIsA("Humanoid")local humanoidDescription = Instance.new("HumanoidDescription")if humanoid thenhumanoidDescription = humanoid:GetAppliedDescription()end
從現有外觀
使用以下代碼示例通過外觀 ID 使用 Players.GetHumanoidDescriptionFromOutfitID 創建 HumanoidDescription:
從外觀 ID 生成 HumanoidDescription
local Players = game:GetService("Players")local outfitId = 480059254local humanoidDescriptionFromOutfit = Players:GetHumanoidDescriptionFromOutfitId(outfitId)
從特定用戶
使用以下代碼示例通過用戶 ID 使用 Players:GetHumanoidDescriptionFromUserId() 創建 HumanoidDescription:
從用戶 ID 生成 HumanoidDescription
local 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。使用以下代碼為玩家角色添加一副新墨鏡和一個新身體:
更新特定玩家角色的 HumanoidDescription
local 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 應用於遊戲中的所有當前玩家:
更新所有當前玩家角色的 HumanoidDescription
local 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 實例是在 Explorer 中創建並掛載到工作區,則可以在 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)