角色外觀

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

大多數體驗允許玩家使用自己的 Roblox 角色,雖然有些則實施類似於 UGC Homestore 模板的遊戲內自訂系統。其他體驗則對玩家角色做出有限的 修改,例如頭盔、翅膀或與類型相匹配的配飾。

要創造一種獨特的體驗以改變您的用戶外觀,您可以透過 角色設定手動修改外觀 自訂預設角色屬性。

全局角色設定

Studio 的 File ⟩ Avatar Settings 允許您快速設置體驗中多個全球玩家角色屬性。這些設定對所有進入您體驗的玩家角色模型全局適用。要修改特定角色,如非玩家角色模型,請參見 手動修改外觀

在此窗口中,您可以設置衣物、配飾、身體部位、碰撞行為、動畫等的多種預設。在編輯這些設定時,應用設定的預覽會在工作區顯示。

欲了解更多資訊,請參見 Avatar Settings

手動修改外觀

角色模型包含一個 Humanoid 對象,為模型提供特殊特徵,例如行走、跳躍、裝備物品以及與環境互動。

您可以透過更新 HumanoidDescription 來編程修改 Humanoid。這包括您體驗中的玩家角色模型或非玩家角色模型。

您可以使用 HumanoidDescription 調整以下角色屬性:

角色屬性描述
比例物理特徵的數值 heightwidthheadbody typeproportion。這不會影響 R6 身體類型。
配飾由角色裝備的 accessories 的資產 ID。
經典衣物您可以應用於角色的 ShirtPantsShirtGraphic 圖像紋理的資產 ID。
身體部位角色的 FaceHeadTorsoRightArmLeftArmRightLegLeftLeg 部位的資產 ID。
身體顏色角色各個部位的 BodyColors
動畫您可以在角色上使用的 Animations 的資產 ID。

使用 HumanoidDescription 自訂角色的步驟如下:

  1. 創建描述,基於用戶的角色、特定的外觀 ID 或特定的用戶 ID。
  2. 修改描述,以自訂您希望應用於 Humanoid 角色的屬性。
  3. 應用描述,可對單個角色、所有玩家角色或甚至所有生成的角色進行應用。

創建 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 then
humanoidDescription = humanoid:GetAppliedDescription()
end

從現有外觀

使用以下代碼示例通過外觀 ID 使用 Players.GetHumanoidDescriptionFromOutfitID 創建 HumanoidDescription

從外觀 ID 生成 HumanoidDescription

local Players = game:GetService("Players")
local outfitId = 480059254
local humanoidDescriptionFromOutfit = Players:GetHumanoidDescriptionFromOutfitId(outfitId)

從特定用戶

使用以下代碼示例通過用戶 ID 使用 Players:GetHumanoidDescriptionFromUserId() 創建 HumanoidDescription

從用戶 ID 生成 HumanoidDescription

local Players = game:GetService("Players")
local userId = 491243243
local humanoidDescriptionFromUser = Players:GetHumanoidDescriptionFromUserId(userId)

修改 HumanoidDescription

要自訂 HumanoidDescription 屬性,直接在 HumanoidDescription 上設置它們,或者使用指定的方法,在將 HumanoidDescription 應用到角色之前進行設置。

以下代碼示例提供了設置不同類型的 HumanoidDescription 屬性的示例:

更新各種 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: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.LoadCharacterWithHumanoidDescriptionHumanoidDescription 應用於您體驗中的特定 Humanoid 角色。

對單個角色

ApplyDescription() 可以針對任何 Humanoid。使用以下代碼為玩家角色添加一副新墨鏡和一個新身體:

更新特定玩家角色的 HumanoidDescription

local humanoid = player.Character and player.Character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
local descriptionClone = humanoid:GetAppliedDescription()
descriptionClone.Torso = 86500008
-- 多個面部配飾資產在逗號分隔的字符串中是允許的
descriptionClone.FaceAccessory = descriptionClone.FaceAccessory .. ",2535420239"
-- 將修改後的 "descriptionClone" 應用於 humanoid
humanoid:ApplyDescription(descriptionClone)
end

對所有玩家角色

使用以下代碼示例將 HumanoidDescription 應用於遊戲中的所有當前玩家:

更新所有當前玩家角色的 HumanoidDescription

local Players = game:GetService("Players")
for _, player in Players:GetPlayers() do
local humanoid = player.Character and player.Character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
-- 創建一個 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)
humanoid:ApplyDescription(humanoidDescription)
end
end

對所有生成的角色

使用以下代碼示例為所有生成的玩家角色設置特定的 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)