Humanoid

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

ヒューマノイドは、モデルにキャラクターの機能を提供する特別なオブジェクトです。それは、モデルに物理的に周りを歩き回り、Roblox の経験のさまざまなコンポーネントと対話する能力を付与します。ヒューマノイドは常に Model の内部に親属し、モデルは BasePartMotor6D のアセンブリを構成することが期待され、アセンブリのルートパーツは HumanoidRootPart と呼ばれる予定です。また、Head という名前のパーツが、直接または間接的にキャラクターの胴体部分に接続することを期待します。デフォルトでは、Roblox によって提供される 2つの公式のキャラクターリグがあり、それぞれに独自のルールセットがあります:

R6

  • 手足のために 6 部分を使用する基本のキャラクターリグ。
  • Head パーツは、Torso という名前のパーツに付属する必要があり、そうしないとヒューマノイドはすぐに死亡します。
  • ボディパーツの外観は、CharacterMesh オブジェクトを使用して適用されます。
  • Humanoid.LeftLegHumanoid.RightLeg などの特定のプロパティは、R6でのみ機能します。

R15

  • R6よりも複雑ですが、より柔軟性と強度があります。
  • 手足のために 15 部品を使用します。
  • Head 部分は、UpperTorso という名前のパーツに付属する必要があり、そうしないとヒューマノイドはすぐに死亡します。
  • ボディパーツの外観は直接組み立てられなければなりません。
  • ヒューマノイド内に親属する特別な NumberValue オブジェクトを使用して、動的にスケールを調整できます。
  • ヒューマノイドは、各肢内に という名前のオブジェクトを自動的に作成します。
  • Humanoid 内に NumberValue が親になっており、以フォロー中のいずれかの名前で名前付けられている場合、スケーリング機能を制御するために使用されます:
    • ボディの深さスケール
    • ボディの高さスケール
    • ボディ幅スケール
    • ヘッドスケール

コードサンプル

Walking Camera Bobble Effect

local RunService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local function updateBobbleEffect()
local now = tick()
if humanoid.MoveDirection.Magnitude > 0 then -- Is the character walking?
local velocity = humanoid.RootPart.Velocity
local bobble_X = math.cos(now * 9) / 5
local bobble_Y = math.abs(math.sin(now * 12)) / 5
local bobble = Vector3.new(bobble_X, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
else
-- Scale down the CameraOffset so that it shifts back to its regular position.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)

概要

プロパティ

方法

イベント

プロパティ

AutoJumpEnabled

並列読み取り

AutoJumpEnabled は、Humanoid が歩いている障害物を自動的に飛び越えるかどうかを設定します。

現在、このプロパティは次の条件が真になるときだけ機能します:

  • ヒューマノイドのキャラクタモデルは、Player.CharacterPlayer です。
  • 問題のプレイヤーはタッチコントロールを使用しています。

プレイヤーのキャラクターがスポーンすると、プロパティの値がプレイヤーの Player.AutoJumpEnabled プロパティと一致します - それは、StarterPlayer.AutoJumpEnabled プロパティに一致します。

コードサンプル

Auto-Jump Toggle

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
local function update()
-- Update button text
if player.AutoJumpEnabled then
button.Text = "Auto-Jump is ON"
else
button.Text = "Auto-Jump is OFF"
end
-- Reflect the property in the player's character, if they have one
if player.Character then
local human = player.Character:FindFirstChild("Humanoid")
if human then
human.AutoJumpEnabled = player.AutoJumpEnabled
end
end
end
local function onActivated()
-- Toggle auto-jump
player.AutoJumpEnabled = not player.AutoJumpEnabled
-- Update everything else
update()
end
button.Activated:Connect(onActivated)
update()

AutoRotate

並列読み取り

AutoRotate プロパティは、ヒューマノイドが移動している方向に自動的に回転するかどうかを説明します。真に設定すると、キャラクターモデルは、ヒューマノイドが周りを歩くにつれて、徐々に移動方向を向くようになります。false に設定すると、キャラクタモデルは、HumanoidRootPart に回転力が適用されない限り、現在の回転に固定されたままです。

キャラクターモデルがプレイヤーのキャラクターである場合、ヒューマノイドの回転の動作は、ユーザーゲーム設定の [回転タイプ] プロパティに影響を受けます。

AutoRotate プロパティが true に設定されると、RotateType プロパティはヒューマノイドの回転に次の効果を持ちます:


<th>動作</th>
<th>コンテンツ</th>
</tr>
</thead>
<tbody>
<tr>
<td>移動関連</td>
<td />
<td />
</tr>
<tr>
<td>カメラ関連</td>
<td>キャラクターはカメラの方向に向いて回転します。</td>
<td>プレイヤーのカメラが一人称モードにズームされているか、またはシフトロックモードにあります。</td>
</tr>
</tbody>
回転タイプ

コードサンプル

AutoRotate Button

local button = script.Parent
local enabled = true
local ON_COLOR = BrickColor.Green()
local OFF_COLOR = BrickColor.Red()
local function touchButton(humanoid)
if enabled then
enabled = false
button.BrickColor = OFF_COLOR
if humanoid.AutoRotate then
print(humanoid:GetFullName() .. " can no longer auto-rotate!")
humanoid.AutoRotate = false
else
print(humanoid:GetFullName() .. " can now auto-rotate!")
humanoid.AutoRotate = true
end
task.wait(1)
button.BrickColor = ON_COLOR
enabled = true
end
end
local function onTouched(hit)
local char = hit:FindFirstAncestorWhichIsA("Model")
if char then
local humanoid = char:FindFirstChildOfClass("Humanoid")
if humanoid then
touchButton(humanoid)
end
end
end
button.Touched:Connect(onTouched)
button.BrickColor = ON_COLOR

AutomaticScalingEnabled

並列読み取り

ヒューマノイドには、BodyDepthScaleBodyHeightScaleBodyProportionScaleBodyTypeScaleBodyWidthScaleHeadScale など、6つの子スケール値があります。これらの値を変更すると、キャラクターの身体部分とアクセサリのサイズが変更されますが、AutomaticScalingEnabled が真になる場合のみです。

BreakJointsOnDeath

並列読み取り

ヒューマノイドの関節が Enum.HumanoidStateType.Dead 状態で破損するかどうかを決定します。デフォルトは true です。

CameraOffset

並列読み取り

CameraOffset プロパティは、Camera.CameraSubject がこの Humanoid に設定されたときのカメラの対象位置へのオフセットを指定します。

オフセットは、ヒューモイドの HumanoidRootPart のオリエンテーションに対してオブジェクトスペースに適用されます。たとえば、オフセット Vector3 値の (0、10、0) オフセットは、プレイヤーのカメラをプレイヤーのヒューマノイド上の 10 スタッドまでオフセットします。

コードサンプル

Walking Camera Bobble Effect

local RunService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local function updateBobbleEffect()
local now = tick()
if humanoid.MoveDirection.Magnitude > 0 then -- Is the character walking?
local velocity = humanoid.RootPart.Velocity
local bobble_X = math.cos(now * 9) / 5
local bobble_Y = math.abs(math.sin(now * 12)) / 5
local bobble = Vector3.new(bobble_X, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
else
-- Scale down the CameraOffset so that it shifts back to its regular position.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)
並列読み取り

ディスプレイ距離タイプ プロパティは、ヒューマノイドの名前と体力表示の距離動作を制御します。このプロパティは、3つの利用可能な値を持つ Enum.HumanoidDisplayDistanceType 枚列を使用して設定されます:それぞれに独自のルールセットがあります:

  • When set to Viewer , the humanoid sees the name/health of other humanoids within range of its own NameDisplayDistanceHealthDisplayDistance .
  • Subject に設定すると、ヒューマノイドは 完全なコントロール を自分の名前と体力表示を通じて NameDisplayDistanceHealthDisplayDistance の値で取得します。
  • None に設定すると、ヒューマノイドの名前と健康バーは、どんな状況でも表示されません。

キャラクター名/ヘルス表示 を参照して、キャラクター名とヘルスバーの外観を制御する詳細ガイドを見る。

コードサンプル

Displaying a Humanoid's Health and Name

local humanoid = script.Parent
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
humanoid.HealthDisplayDistance = 0
humanoid.NameDisplayDistance = 100

DisplayName

並列読み取り

DisplayName は、視覚的に表示されるときにヒューマノイドの名前表示を決定するプロパティです。デフォルトでは、新しいヒューマノイドは空の文字列の値を持つようになります。if DisplayName が空の文字列の場合、ヒューマノイドの名前表示は、ヒューマノイドの親の名前プロパティにデフォルトで設定されます。

プレイヤーキャラクターロード

プレイヤーがキャラクターをロードすると、自動的に、または LoadCharacter() を使用して、エンジンによって作成されたヒューマノイドの DisplayName プロパティが、プレイヤーの DisplayName プロパティに設定されます。

スターターキャラクターとスターターヒューモイド

という名前の が に親属したとき、または という名前のモデルにヒューマノイドが存在したとき、ゲーム内のプレイヤーによってキャラクターがロードされると、DisplayName プロパティが尊重されます。エンジンは、 プロパティを Humanoid の プロパティでオーバーライドするだけで、 の が空の文字列である場合、プレイヤーの プロパティをオーバーライドします。

EvaluateStateMachine

並列読み取り

FloorMaterial

読み取り専用
複製されていません
並列読み取り

これは、現在立っている Enum.MaterialHumanoid を説明する読み取り専用プロパティです。正規の PartsTerrain ボクセルの両方で動作します。

以下のコードサンプルでは、Object:GetPropertyChangedSignal() を使用してこのプロパティが変更されるときに聞く方法を示しています。ヒューマノイドが立っている物質が変更されると、新しい物質が立っていることを示すメッセージが印刷されます。


local Humanoid = route.to.humanoid
Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
print("New value for FloorMaterial: " .. tostring(Humanoid.FloorMaterial))
end)

注意事項

  • Humanoid が床に立っていないとき、このプロパティの値は 空気 に設定されます。
    • これは、Enum プロパティに空の値を持つことができないためです。
    • これは、パーツの材料が空気に設定されている場合、混乱を引き起こす可能性がありますが、実際には、パーツは最プレースからその材料を使用することはありません。
  • Humanoid のキャラクタモデルは、床と衝突できる必要があり、そうでなければ検出されません。
    • Humanoid がこのプロパティで泳いでいるかどうかをテストすることはできません。代わりに、その Humanoid:GetState() 機能を使用する必要があります。

Health

複製されていません
並列読み取り

このプロパティは、Humanoid の現在の健康を表示します。値は 0 と MaxHealth の間の範囲に制限されます。ヒューマノイドが死亡した場合、このプロパティは連続して 0 に設定されます。

Note that the TakeDamage() 関数は、プロパティを直接設定するのではなく、Health から差し引くために使用できます。

健康再生

デフォルトでは、パッシブヘルス再生スクリプトが自動的にヒューマノイドに挿入されます。これにより、死亡しないプレイヤーキャラクターが、毎秒 1% の MaxHealth を再生します。この再生行動を無効にするには、Script に名前付きの空の 健康 を追加し、StarterCharacterScripts に追加します。

ヘルスバーの表示

HealthMaxHealth より小さいとき、エクスペリエンス内にヘルスバーが表示されます。ヘルスバーの表示動作は、HealthDisplayDistanceHealthDisplayType に依存します。

キャラクター名/ヘルス表示 を参照して、キャラクター名とヘルスバーの外観を制御する詳細ガイドを見る。

キャラクターの健康値が 0 に達すると、Humanoid は自動的に Enum.HumanoidStateType.Dead 状態に移行します。この状態では、Health は 0 にロックされていますが、死のヒューマノイドの Health を正の非ゼロ値に設定するためのエラーや警告はありません。

HealthDisplayDistance

並列読み取り

このプロパティは、DisplayDistanceType プロパティと一緒に使用されて、ヒューマノイドのヘルスバーが見える距離を制御するために使用される数値です。

キャラクター名/ヘルス表示 を参照して、キャラクター名とヘルスバーの外観を制御する詳細ガイドを見る。

並列読み取り

このプロパティは、ヒューマノイドのヘルスバーが表示される時間を制御します。デフォルトでは、このプロパティは DisplayWhenDamaged に設定され、ヒューマノイドの Health がその MaxHealth より少ないときにのみヘルスバーが表示されます。また、健康バーを常に表示するように AlwaysOn 、または表示しないように AlwaysOff に設定できます。

このプロパティは、特定の距離でヘルスバーが消えるのを責任とするヒューマノイドの HealthDisplayDistance プロパティとは独立して機能します。If Humanoid.HealthDisplayType|HealthDisplayTypeAlwaysOn に設定されている場合、どのように HealthDisplayDistance が構成されているかに応じて依然として消えます。

キャラクター名/ヘルス表示 を参照して、キャラクター名とヘルスバーの外観を制御する詳細ガイドを見る。

HipHeight

並列読み取り

ヒューマノイドが立っているときに RootPart が持つ距離 (スタッド) を決定します。The RigType は、このプロパティの動作方法に影響を与えます。

R15 の装備の場合、適切なヒップの高さがプリセットされて、RootPart の高さが正しいことを保証します。脚の高さは使用されません。ヒューマノイドの総高さは次の式で説明できます:


Height = (0.5 * RootPart.Size.Y) + HipHeight

R6 リグの場合、HipHeight 代わりに相対オフセットを説明します。ヒューマノイドの総高さは次の式で説明できます:


Height = LeftLeg.Size.Y + (0.5 * RootPart.Size.Y) + HipHeight
複製されていません
並列読み取り

If true , the Humanoid jumps with an upwards force equal to the value of Humanoid.JumpPower または高さの Humanoid.JumpHeight , depending on the value of Humanoid.UseJumpPower .

JumpHeight

並列読み取り

スタッドで Humanoid ジャンプの高さを制御します。このプロパティの開始値は、デフォルトで 7.2 になる StarterPlayer.CharacterJumpHeight の値によって決まります。

このプロパティを 0 に設定すると、ヒューマノイドのジャンプを効果的に防ぐことができますが、 状態を無効にしてジャンプを無効にすることをお勧めします。

このプロパティは、 プロパティ ウィンドウでのみ表示されますが、そうでなければ関連がないため (代わりに、 が使用されます)、そうでなければ に設定されます。

JumpPower

並列読み取り

ジャンプ時に Humanoid にどのくらい上向き力が適用されるかを決定します。このプロパティの開始値は、デフォルトで 50 に設定され、0から1000の間に制限される StarterPlayer.CharacterJumpPower の値によって決まります。ジャンプは、重力による加速を決定する Workspace.Gravity プロパティにも影響を受けます。

このプロパティを 0 に設定すると、ヒューマノイドのジャンプを効果的に防ぐことができますが、 状態を無効にしてジャンプを無効にすることをお勧めします。

このプロパティは、 プロパティ ウィンドウでのみ表示されますが、そうでなければ関連がないため (代わりに、 が使用されます)、そうでなければ true に設定されます。

MaxHealth

並列読み取り

ヒューマノイドの Health の最大値。

このプロパティの値は、デフォルトのヘルスバー表示をサイズするために Health プロパティと一緒に使用されます。ヒューマノイドの HealthMaxHealth に達すると、健康バーが表示されない可能性があります。その HealthDisplayType プロパティによります。

MaxSlopeAngle

並列読み取り

このプロパティは、ヒューマノイドが登ることができる最大傾き角を決定します。坂の角度がヒューマノイドの MaxSlopeAngle より大きい場合、坂を下にスライドします。

キャラクターがスポーンすると、このプロパティは StarterPlayer.CharacterMaxSlopeAngle の値に従って設定されます。

このプロパティの値は、0°から 89°の間の値に制限されます。デフォルトで 89° になるので、ヒューマノイドはデフォルトで望むほぼどんな坂を登ることができます。

コードサンプル

Limiting The Slope a Humanoid Can Walk Up

local player = game.Players.LocalPlayer
local char = player.CharacterAdded:wait()
local h = char:FindFirstChild("Humanoid")
h.MaxSlopeAngle = 30

MoveDirection

読み取り専用
複製されていません
並列読み取り

移動方向 は、単位ベクトルまたは長さゼロのベクトルとして、Humanoidが歩いている方向を記述する読み取り専用のプロパティです。方向はワールドスペースで説明されます。

このプロパティは読み込み専用なので、Script または LocalScript で設定することはできません。

コードサンプル

Walking Camera Bobble Effect

local RunService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local function updateBobbleEffect()
local now = tick()
if humanoid.MoveDirection.Magnitude > 0 then -- Is the character walking?
local velocity = humanoid.RootPart.Velocity
local bobble_X = math.cos(now * 9) / 5
local bobble_Y = math.abs(math.sin(now * 12)) / 5
local bobble = Vector3.new(bobble_X, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
else
-- Scale down the CameraOffset so that it shifts back to its regular position.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)

NameDisplayDistance

並列読み取り

名前表示距離 プロパティは、Humanoid.DisplayDistanceType プロパティと一緒に使用される数値で、ヒューマノイドの名前が見える距離を制御します。

キャラクター名/ヘルス表示 を参照して、キャラクター名とヘルスバーの外観を制御する詳細ガイドを見る。

NameOcclusion

並列読み取り

ヒューマノイドの名前と健康バーが壁や他のオブジェクトの後ろで見えるかどうかを制御します。このプロパティは Enum.NameOcclusion 値であり、すべての名前、敵の名前、または完全にオクラジョンを無効にするように構成できます。

LocalPlayer に関連する Humanoid がない場合、このプロパティは、代わりに対象 Humanoid に適用されます。

キャラクター名/ヘルス表示 を参照して、キャラクター名とヘルスバーの外観を制御する詳細ガイドを見る。

コードサンプル

Occlude Player Names

local Players = game:GetService("Players")
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.NamOcclusion = Enum.NameOcclusion.OccludeAll
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

PlatformStand

並列読み取り

現在 HumanoidEnum.HumanoidStateType.PlatformStanding 状態にあるかどうかを決定します。真になると、ヒューマノイドは自由落下して動けない状態になります。この状態は、ジャンプで人形を状態から解放しないことを除き、座ると同様の動作を行います。

RequiresNeck

並列読み取り

開発者が、ネック が一時的に削除されたり切断されたりしても、プレイヤーが死亡する動作を無効にすることを許可します。このプロパティはデフォルトで真になります。

並列読み取り

装備タイプ は、Humanoid がレガシーの R6 キャラクターリグ、または新しい R15 キャラクターリグを使用しているかどうかを説明します。

R6 装置は 6 個の表示可能な Parts を使用し、R15 装置は 15 個の表示可能な Parts を使用します。R15 リグは、R6 リグよりも多くの関節を持っており、アニメーションするときにはるかに多機能になります。

このプロパティが正しく設定されていない場合、Humanoid は正しく機能しません。たとえば、R15 ヒューマノイドの リグタイプ が R6 に設定されている場合、 は呼び出されていない が トルソ に接続されているため、死亡します。

RootPart

読み取り専用
複製されていません
並列読み取り

ヒューマノイドの HumanoidRootPart オブジェクトへの参照、ヒューマノイドの動作を 3D 世界で制御する Humanoid の根部ドライブ部分。この部分は通常見えません。

R15 キャラクターの場合、Model.PrimaryPart モデルの Player.CharacterHumanoidRootPart に設定されます。

R6 キャラクターの場合、Model.PrimaryPartHead 部分に設定されます。

SeatPart

読み取り専用
複製されていません
並列読み取り

シートパーツは、Humanoid が現在座っているシートに対する参照で、必要に応じています。このプロパティの値は、Seat または VehicleSeat であることができます。Humanoidが現在座っていない場合は、ゼロになります。

注意:

  • Humanoid が現在座っているかどうかを説明する bool については、Humanoid.Sit を参照してください
並列読み取り

Sit プロパティは、Humanoid が現在座っているかどうかを示すブールです。Humanoids このプロパティの値を真に設定することで、座った状態に強制することができます。Humanoid が座っている状態でシートに付属していない場合、腿に衝突せずに転倒します。A Humanoid はジャンプして座っている状態から脱出できます。

注意:

TargetPoint

並列読み取り

使用しない このプロパティは、廃止された試験モードを有効にした状態でのみ機能します。

このプロパティは、Player が装備された状態で最後にクリックした 3D 位置を空間で説明します。この Humanoid は、Tool で制御されています。

このプロパティは、主にクラシックツールが有効にすると、人形がターゲットにしているものを決定するのに使用されます。NPCにクラシックなロケットランチャーを与え、 ターゲットポイント を設定し、ツールのTool:Activate()を呼び出すと、NPCがターゲットポイントでロケットを発射できます。

UseJumpPower

並列読み取り

キャラクターがスポーンすると、このプロパティは、デフォルトで真に設定される StarterPlayer.CharacterUseJumpPower の値に従って設定されます。

ジャンプするとき、これを真に設定すると、Humanoid.JumpHeight 値が使用されて、ヒューマノイドがその高さにジャンプすることを保証します。これを false に設定すると、Humanoid.JumpPower 値が上向きの力を適用するのに使用されます。

WalkSpeed

並列読み取り

このプロパティは、Humanoid が毎秒どのくらい速く歩行けるかを説明します。デフォルトでは、StarterPlayer.CharacterWalkSpeed (16)の値になり、プレイヤーキャラクターは毎秒どの方向にも 16スタッド移動できます。

ノート

  • モバイルデバイスまたはゲームパッドで制御すると、ヒューマノイドは、操作スティックを中心から少しずつ移動させると、WalkSpeed より遅く歩行できます。
  • WalkSpeed を 0 に設定して、ヒューマノイドを場所に凍結できます;これにより、コントロールプレイヤーがデフォルトの移動メカニズムを通じて移動するのを防ぎます。
  • デフォルトのアニメーションスクリプトは、16スタッド/秒のデフォルト速度に対してどれほど速く移動しているかに基づいて、ヒューマノイドの移動アニメーションをスケールします。
  • 現在 Humanoid が歩いている速度は、Running イベントを使用して取得できます。

WalkToPart

並列読み取り

WalkToPart は、ヒューマノイドが到達しようとしているパーツへの参照です。このプロパティは、通常、パーツがヒューノイドの Humanoid:MoveTo() 関数の 2番目の引数としてパスされるときに設定されます。

WalkToPart が設定され、ヒューマノイドがパーツに到達しようと積極的に試みているとき、パーツの位置となるベクトル 3 の目標を更新し続け、パーツの回転に対してオブジェクトスペースで翻訳された Humanoid.WalkToPoint を保持します。

これは Luau で以下のように説明できます:


goal = humanoid.WalkToPart.CFrame:pointToObjectSpace(humanoid.WalkToPoint)

注意事項

  • WalkToPart の値を設定するだけで、人形がパーツに続いて始まるようにするのに十分ではありません。
  • ヒューマノイドは、WalkToPoint の値が変更されたときに目標に到達するように試みを開始するように促されます。
  • 将来変更される可能性があります。
  • ヒューマノイドの ゴールに到達する状態 は、目標に到達しない場合、8秒後に期限切れになります。
  • これは、NPCが Humanoid.MoveToFinished 発射を待って立ち往生しないようにするために行われます。
  • これが起こらないようにするには、タイムアウトがリセットされ続けるように、MoveTo を複数回呼び出す必要があります。

WalkToPoint

並列読み取り

WalkToPoint は、ヒューマノイドが到達しようとしている空間の 3D 位置を説明し、ヒューマノイドの Humanoid:MoveTo() 機能によってそうするよう促された後です。

ヒューマノイドの Humanoid.WalkToPart が設定する定されている場合、目標はパーツの位置と回転に関連付けて WalkToPoint を変換することで設定されます。WalkToPart が設定する定されていない場合、ヒューマノイドは WalkToPoint に指定された 3D 位置に直接到達しようとします。

注意事項

  • ヒューマノイドがそれに向かって歩き始めるには、WalkToPoint の値が異なる値に変更されなければなりません。
  • 人間の歩行を 0,0,0 に移動したい場合、人間の移動機能を使用する必要があります。
  • 将来変更される可能性があります。
  • ヒューマノイドの ゴールに到達する状態 は、目標に到達しない場合、8秒後に期限切れになります。
  • これは、NPCが Humanoid.MoveToFinished 発射を待って立ち往生しないようにするために行われます。
  • これが起こらないようにするには、タイムアウトがリセットされ続けるように、MoveTo を複数回呼び出す必要があります。

コードサンプル

Humanoid MoveTo Without Time out

local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- listen for the humanoid reaching its target
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- start walking
humanoid:MoveTo(targetPoint)
-- execute on a new thread so as to not yield function
task.spawn(function()
while not targetReached do
-- does the humanoid still exist?
if not (humanoid and humanoid.Parent) then
break
end
-- has the target changed?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresh the timeout
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- disconnect the connection if it is still connected
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "Destination reached!") or "Failed to reach destination!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)

方法

AddAccessory

()

このメソッドは、指定された Accessory をヒューマノイドの親に付けます。

このメソッドが呼ばれると、人形の親で同じ名前の Accessory を検索して、キャラクターに Attachment が付加され、アクセサリの AttachmentハンドルPart が付加されます。もし一つが見つかれば、 ハンドル 部分が を使用して親に接続され、接着が構成されるため、 が同じスペースを占有します。

必要な Attachment が見つからない場合、Accessory はヒューマノイドの親に依存し続けますが、切断されます。

通常、アクセサリー接合はサーバー上で作成されますが、特定の状況でクライアント上で作成できます。これらの状況では、クライアント側の呼び出し AddAccessory() が常に望ましい動作を生成しない可能性があり、BuildRigFromAttachments() を使用して期待される接着の作作品を強制できます。

パラメータ

accessory: Instance

付属する Accessory

既定値: ""

戻り値

()

コードサンプル

[Humanoid] AddAccessory Example

local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local clockworksShades = Instance.new("Accessory")
clockworksShades.Name = "ClockworksShades"
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Size = Vector3.new(1, 1.6, 1)
handle.Parent = clockworksShades
local faceFrontAttachment = Instance.new("Attachment")
faceFrontAttachment.Name = "FaceFrontAttachment"
faceFrontAttachment.Position = Vector3.new(0, -0.24, -0.45)
faceFrontAttachment.Parent = handle
local mesh = Instance.new("SpecialMesh")
mesh.Name = "Mesh"
mesh.Scale = Vector3.new(1, 1.3, 1)
mesh.MeshId = "rbxassetid://1577360"
mesh.TextureId = "rbxassetid://1577349"
mesh.Parent = handle
humanoid:AddAccessory(clockworksShades)

BuildRigFromAttachments

()

このメソッドは、Motor6D のジョイントのツリーを作成し、Humanoid にはジョイントが必要です。Motor6D ジョイントは、Animations の再生に必要です。

ヒューマノイドの から始まり、このメソッドは、名前が RigAttachment で終わる現在のパーツのすべてを収集します。その後、同じ名前の添付ファイルを共有するキャラクターで一致する添付ファイルを検索します。これらの2つの添付ファイルを使用すると、2つの添付ファイルと添付ファイルの Motor6D のパーツに関連するパーツに基づいて、CFrame ジョイントが生成されます。

Humanoid:BuildRigFromAttachments() も、キャラクターをスケールし、ボディの色を設定します。


戻り値

()

コードサンプル

Lua Port of BuildRigFromAttachments

local function createJoint(jointName, att0, att1)
local part0, part1 = att0.Parent, att1.Parent
local newMotor = part1:FindFirstChild(jointName)
if not (newMotor and newMotor:IsA("Motor6D")) then
newMotor = Instance.new("Motor6D")
end
newMotor.Name = jointName
newMotor.Part0 = part0
newMotor.Part1 = part1
newMotor.C0 = att0.CFrame
newMotor.C1 = att1.CFrame
newMotor.Parent = part1
end
local function buildJointsFromAttachments(part, characterParts)
if not part then
return
end
-- first, loop thru all of the part's children to find attachments
for _, attachment in pairs(part:GetChildren()) do
if attachment:IsA("Attachment") then
-- only do joint build from "RigAttachments"
local attachmentName = attachment.Name
local findPos = attachmentName:find("RigAttachment")
if findPos then
-- also don't make double joints (there is the same named
-- rigattachment under two parts)
local jointName = attachmentName:sub(1, findPos - 1)
if not part:FindFirstChild(jointName) then
-- try to find other part with same rig attachment name
for _, characterPart in pairs(characterParts) do
if part ~= characterPart then
local matchingAttachment = characterPart:FindFirstChild(attachmentName)
if matchingAttachment and matchingAttachment:IsA("Attachment") then
createJoint(jointName, attachment, matchingAttachment)
buildJointsFromAttachments(characterPart, characterParts)
break
end
end
end
end
end
end
end
end
local function buildRigFromAttachments(humanoid)
local rootPart = humanoid.RootPart
assert(rootPart, "Humanoid has no HumanoidRootPart.")
local characterParts = {}
for _, descendant in ipairs(humanoid.Parent:GetDescendants()) do
if descendant:IsA("BasePart") then
table.insert(characterParts, descendant)
end
end
buildJointsFromAttachments(rootPart, characterParts)
end
local humanoid = script.Parent:WaitForChild("Humanoid")
buildRigFromAttachments(humanoid)
R15 Package Importer

local AssetService = game:GetService("AssetService")
local InsertService = game:GetService("InsertService")
local MarketplaceService = game:GetService("MarketplaceService")
local PACKAGE_ASSET_ID = 193700907 -- Circuit Breaker
local function addAttachment(part, name, position, orientation)
local attachment = Instance.new("Attachment")
attachment.Name = name
attachment.Parent = part
if position then
attachment.Position = position
end
if orientation then
attachment.Orientation = orientation
end
return attachment
end
local function createBaseCharacter()
local character = Instance.new("Model")
local humanoid = Instance.new("Humanoid")
humanoid.Parent = character
local rootPart = Instance.new("Part")
rootPart.Name = "HumanoidRootPart"
rootPart.Size = Vector3.new(2, 2, 1)
rootPart.Transparency = 1
rootPart.Parent = character
addAttachment(rootPart, "RootRigAttachment")
local head = Instance.new("Part")
head.Name = "Head"
head.Size = Vector3.new(2, 1, 1)
head.Parent = character
local headMesh = Instance.new("SpecialMesh")
headMesh.Scale = Vector3.new(1.25, 1.25, 1.25)
headMesh.MeshType = Enum.MeshType.Head
headMesh.Parent = head
local face = Instance.new("Decal")
face.Name = "face"
face.Texture = "rbxasset://textures/face.png"
face.Parent = head
addAttachment(head, "FaceCenterAttachment")
addAttachment(head, "FaceFrontAttachment", Vector3.new(0, 0, -0.6))
addAttachment(head, "HairAttachment", Vector3.new(0, 0.6, 0))
addAttachment(head, "HatAttachment", Vector3.new(0, 0.6, 0))
addAttachment(head, "NeckRigAttachment", Vector3.new(0, -0.5, 0))
return character, humanoid
end
local function createR15Package(packageAssetId)
local packageAssetInfo = MarketplaceService:GetProductInfo(packageAssetId)
local character, humanoid = createBaseCharacter()
character.Name = packageAssetInfo.Name
local assetIds = AssetService:GetAssetIdsForPackage(packageAssetId)
for _, assetId in pairs(assetIds) do
local limb = InsertService:LoadAsset(assetId)
local r15 = limb:FindFirstChild("R15")
if r15 then
for _, part in pairs(r15:GetChildren()) do
part.Parent = character
end
else
for _, child in pairs(limb:GetChildren()) do
child.Parent = character
end
end
end
humanoid:BuildRigFromAttachments()
return character
end
local r15Package = createR15Package(PACKAGE_ASSET_ID)
r15Package.Parent = workspace

ChangeState

()

このメソッドは、Humanoid が指定された Enum.HumanoidStateType に入り、Humanoid が現在行っているアクティビティを説明します。

特定の状態に関する詳細情報については、Enum.HumanoidStateType ページを確認してください、一部は直感的でない名前を持っています。たとえば、Enum.HumanoidStateType.Running は、ヒューマノイドの脚が地面にある状態、静止時を含む状態を説明します。

Humanoid のデフォルト動作により、いくつかの状態が設設定するされると自動的に変更されます。例えば:

この方法を使用して 状態を設定するには、 からそうする必要があり、クライアントは ネットワーク所有権 を持っている必要があります。代わりに、このメソッドをサーバー側から呼び出すこともできます Script 、しかし、サーバーはプレイヤーキャラクターのネットワーク所有権を持っている必要があります。

特定の状態を有効化または無効化するには、Humanoid:SetStateEnabled() を参照し、現在のヒューマノイド状態を取得するには、Humanoid:GetState() を参照してください。

パラメータ

The Enum.HumanoidStateType は、Humanoid が実行するものです。

既定値: "None"

戻り値

()

コードサンプル

Double Jump

local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local doubleJumpEnabled = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not doubleJumpEnabled then
task.wait(0.2)
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
doubleJumpEnabled = true
end
end
elseif newState == Enum.HumanoidStateType.Landed then
doubleJumpEnabled = false
end
end)
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.Space then
if doubleJumpEnabled then
if humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
task.spawn(function()
doubleJumpEnabled = false
end)
end
end
end
end)

EquipTool

()

このメソッドは、Humanoid に指定された Tool を装備します。

以下の例では、Player がツールを装備することにより、名前が Workspace の ** が生成されます。


local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local player = Players:FindFirstChildOfClass("Player")
if player and player.Character then
local humanoid = player.Character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
local tool = Workspace:FindFirstChild("Tool")
if tool then
humanoid:EquipTool(tool)
end
end
end

このメソッドが呼ばれると、Humanoid はまず、現在装備しているすべての Tools を自動的に装備解除します。

装備されるものの、Tools について、Tool.RequiresHandletrue に機能しないのは、このメソッドを使用して装備するかどうかにかかわらず、ハンドルがない場合です。

参照してください:

パラメータ

tool: Instance

装備する Tool

既定値: ""

戻り値

()

GetAccessories

このメソッドは、ヒューマノイドの親が現在着用しているオブジェクトのアレイを返します Accessory 。すべてのこのような Accessory オブジェクトが含まれ、付属しているかどうかにかかわらずです。

HumanoidAccessory オブジェクトがない場合、空の配列が返されます。

参照してください Humanoid:AddAccessory() 人形の親に Accessory を付けるために。


戻り値

ヒューマノイドの親に属するオブジェクトの配列 Accessory

コードサンプル

Remove Accessories After Loading

local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- All accessories have loaded at this point
local humanoid = character:FindFirstChildOfClass("Humanoid")
local numAccessories = #humanoid:GetAccessories()
print(("Destroying %d accessories for %s"):format(numAccessories, player.Name))
humanoid:RemoveAccessories()
end)
-- Make sure we disconnect our connection to the player after they leave
-- to allow the player to get garbage collected
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)

GetAppliedDescription

このメソッドは、人形のキャッシュされた HumanoidDescription のコピーを返し、現在の外観を説明します。これを使用して、キャラクターの外観を迅速に決定し、Humanoid:ApplyDescription() メソッドを使用して他のキャラクターに外観を割り当てることができます。

参照してください: See Also


戻り値

GetBodyPartR15

このメソッドは、Enum.BodyPartR15 何が Part であるか、または、パーツが R15 ボディパーツでない場合は Enum.BodyPartR15.Unknown を返します。このメソッドでは、開発者が実際のボディパーツ名と無関係にプレイヤーのボディパーツを取得でき、代わりに枚数を返すことができます。

Humanoid:ReplaceBodyPartR15() と一緒に使用できます。たとえば、プレイヤーの身体部分が何かに触れると、この関数はパーツインスタンスを取得します。開発者は、頭や腕のような体の部分を調べることができます。次に、その部分が何であったかによって、開発者はゲームプレイアクションを実行するか、その部分を他の部分と交換して置き換えるか、おそらくダメージを表示するかもしれません。

このメソッドは、ヒット位置が重要なゲームに有用です。たとえば、プレイヤーが脚に打たれているかどうかを判断し、その後、怪我に基づいて減速させることができます。

パラメータ

part: Instance

指定された部分が R15 ボディパーツかどうかをチェックする。

既定値: ""

戻り値

指定された部分の R15 ボディパーツタイプまたは、部分がボディパーツでない場合は不明です。

GetLimb

このメソッドは、Enum.Limb 指定された Part に関連する enum を返します。例えば、R15とR6の両方の装置で機能します:


-- R15 用
print(humanoid:GetLimb(character.LeftUpperLeg)) -- Enum.Limb.LeftLeg
print(humanoid:GetLimb(character.LeftLowerLeg)) -- Enum.Limb.LeftLeg
print(humanoid:GetLimb(character.LeftFoot)) -- Enum.Limb.LeftLeg
-- R6 の場合
print(humanoid:GetLimb(character:FindFirstChild("Left Leg"))) -- Enum.Limb.LeftLeg

パーツの親がヒューマノイドの親に設定されていない場合、Humanoid:GetLimb() でエラーが発生します。

パラメータ

part: Instance

Part で、Enum.Limb が回収される予定のもの。

既定値: ""

戻り値

一致するパーツの Enum.Limb

コードサンプル

Getting a Humanoid's Limbs

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
for _, child in pairs(character:GetChildren()) do
local limb = humanoid:GetLimb(child)
if limb ~= Enum.Limb.Unknown then
print(child.Name .. " is part of limb " .. limb.Name)
end
end

GetMoveVelocity


戻り値

並列書き込み

このメソッドは、人形の現在の Enum.HumanoidStateType を返し、Humanoid が現在行っている活動を説明します、例えばジャンプやスイミング。

特定の状態を有効化または無効化するには、Humanoid:SetStateEnabled() を参照し、現在のヒューマノイド状態を変更するには、Humanoid:ChangeState() を参照してください。


戻り値

コードサンプル

Double Jump

local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local doubleJumpEnabled = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not doubleJumpEnabled then
task.wait(0.2)
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
doubleJumpEnabled = true
end
end
elseif newState == Enum.HumanoidStateType.Landed then
doubleJumpEnabled = false
end
end)
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.Space then
if doubleJumpEnabled then
if humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
task.spawn(function()
doubleJumpEnabled = false
end)
end
end
end
end)

GetStateEnabled

並列書き込み

GetStateEnabled メソッドは、Enum.HumanoidStateType が有効になっているかどうか、Humanoid に対してを返します。

ヒューマノイド状態は、ヒューマノイドが現在行っている活動を記述します。

特定の Enum.HumanoidStateType が無効になると、ヒューマノイドはその状態に入ることができません。これは、状態を変更する試みが Humanoid:ChangeState() または Roblox 内のヒューマノイドコードを使用して行われているかどうかに関係なく、真実です。

参照してください:

  • ヒューマノイド状態が有効になったり無効になったときに発動するイベントについては、Humanoid.StateEnabledChanged
  • Class.Humanoid``Class.Humanoid:SetStateEnabled()

パラメータ

指定された Enum.HumanoidStateType

既定値: ""

戻り値

指定された Enum.HumanoidStateType が有効になっているかどうか。

コードサンプル

Setting and Getting Humanoid States

local humanoid = script.Parent:WaitForChild("Humanoid")
-- Set state
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
-- Get state
print(humanoid:GetStateEnabled(Enum.HumanoidStateType.Jumping)) -- false

Move

()

このメソッドは、 が指定された方向に歩くようにします。

デフォルトでは、方向は世界単規約ですが、relativeToCamera パラメータが true である場合、方向は CFrameCurrentCamera に相対します。RobloRoblox(ロブロックス) では、ネガティブな Z 方向が「前方」と考えられているため、次のコードでは、ヒューマノイドが CurrentCamera 方向に歩くことになります。


humanoid:Move(Vector3.new(0, 0, -1), true)

このメソッドが呼ばれると、Humanoid はメソッドが再度呼ばれるまで移動します。しかし、このメソッドは次のフレームで Roblox のデフォルトキャラクターコントロールスクリプトによって上書きされます。これは、RunService:BindToRenderStep() (例を参照) でこの関数をすべてのフレームで呼び出し、または StarterPlayerScripts でコントロールスクリプトを上書きすることで回避できます。

このメソッドはサーバーで呼び出すことができますが、これはサーバーがヒューマノイドのアセンブリの ネットワーク所有権 を持っているときにのみ行うべきです。

また、 を見てください、これはポイントへの 歩行を行い、効果的にこの関数を呼び出します。

パラメータ

moveDirection: Vector3

歩行する方向。

既定値: ""
relativeToCamera: boolean

true パラメータがmoveDirection に相対するものである必要がある場合は、CurrentCamera に設定します。

既定値: false

戻り値

()

コードサンプル

Moving a Humanoid Forwards

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
RunService:BindToRenderStep("move", Enum.RenderPriority.Character.Value + 1, function()
if player.Character then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid:Move(Vector3.new(0, 0, -1), true)
end
end
end)

MoveTo

()

このメソッドは、HumanoidHumanoid.WalkToPoint および Humanoid.WalkToPart プロパティを設定して、指定された場所に歩くようにします。

ロケーションパーツ パラメータは、Humanoid.WalkToPointHumanoid.WalkToPart が設定されるものと一致します。

パーツ パラメータが指定されている場合、Humanoid はまだその場所に歩く試みを行います。しかし、パーツが移動すると、Humanoid を指すポイントは、パーツと同じ位置に移動します パーツに対してパーツ パラメータが指定されない場合、Humanoid を歩いている位置は変更されません。

ヒューマノイドの ゴールに到達する状態 は、目標に到達しない場合、8秒後に期限切れになります。これは、NPCがHumanoid.MoveToFinished発射を待って立ち往生しないようにするために行われます。これが起こらないようにするには、タイムアウトがリセットされ続けるように、MoveTo を複数回呼び出す必要があります。

MoveTo() 以下の条件のいずれかが適用されると、終了します:

  • キャラクターが目的地に到着します。

  • キャラクターが固定し、8秒のタイマーが切れます。

  • 値は、Humanoid.WalkToPoint または Humanoid.WalkToPart が変更されます。

  • スクリプトが新しい Humanoid:Move() パラメータで moveDirection を呼び出します。

  • スクリプトは、CFrameRootPart プロパティを変更します。

パラメータ

location: Vector3

Humanoid.WalkToPoint を設定する位置。

既定値: ""
part: Instance

設定する を設定する。

既定値: "nil"

戻り値

()

コードサンプル

Humanoid MoveTo Without Time out

local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- listen for the humanoid reaching its target
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- start walking
humanoid:MoveTo(targetPoint)
-- execute on a new thread so as to not yield function
task.spawn(function()
while not targetReached do
-- does the humanoid still exist?
if not (humanoid and humanoid.Parent) then
break
end
-- has the target changed?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresh the timeout
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- disconnect the connection if it is still connected
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "Destination reached!") or "Failed to reach destination!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)

RemoveAccessories

()

このメソッドは、ヒューマノイドの親が着用しているすべての Accessory オブジェクトを削除します。プレイヤーの Characters にとって、これはすべての帽子とその他のアクセサリーを削除します。

このメソッドは、 オブジェクトを呼び出して削除し、つまりアクセサリの が に設定され、ロックされます。

参照してください Humanoid:AddAccessory()Accessory を付けて、そして Humanoid:GetAccessories()Accessory すべてのオブジェクトを取得して、Humanoid に属するオブジェクトを取得します。


戻り値

()

コードサンプル

Remove Accessories After Loading

local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- All accessories have loaded at this point
local humanoid = character:FindFirstChildOfClass("Humanoid")
local numAccessories = #humanoid:GetAccessories()
print(("Destroying %d accessories for %s"):format(numAccessories, player.Name))
humanoid:RemoveAccessories()
end)
-- Make sure we disconnect our connection to the player after they leave
-- to allow the player to get garbage collected
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)

ReplaceBodyPartR15

人形に R15/Rthro の肢部パーツを動的に置き換え、異なるパーツで置き換えます。パーツは通常通り自動スケーリングされます。

このメソッドは、ゲームプレイ中にキャラクターを変更するか、ベースのリグからキャラクターを作成するのに便利です。関連するメソッド GetBodyPartR15 は、このメソッドを使用するとき便利になる可能性があります。

パーツを渡された名前は、BodyPartR15 Enum で渡された名前と一致する必要があります。

パラメータ

交換するボディパーツ。Enum.BodyPartR15.Unknown は失敗します。

既定値: ""
part: BasePart

キャラクターに親属する Class.Part``Class.Instance が指定される。

既定値: ""

戻り値

SetStateEnabled

()

このメソッドは、指定された Enum.HumanoidStateTypeHumanoid に有効かどうかを設定します。特定の Enum.HumanoidStateType が無効になると、Humanoid はその状態に入ることができません。これは、状態を変更する試みが Humanoid:ChangeState() または Roblox 内部の Humanoid コードを使用して行われているかどうかに関係なく、真実です。

サーバー上で SetStateEnabled() を使用すると、クライアントに変更が反映されることはありません。また、その逆も同様です。

パラメータ

有効化または無効化する Enum.HumanoidStateType

既定値: ""
enabled: boolean

true if state が有効になる必要がある場合、false if state が無効になる必要がある場合。

既定値: ""

戻り値

()

コードサンプル

Jump Cooldown

local character = script.Parent
local JUMP_DEBOUNCE = 1
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not isJumping then
isJumping = true
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
elseif newState == Enum.HumanoidStateType.Landed then
if isJumping then
isJumping = false
task.wait(JUMP_DEBOUNCE)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
end)

TakeDamage

()

このメソッドは、Humanoid.HealthHumanoid を、指定された で低下させます if it is not protected by a ForceField

このメソッドは、 パラメータにネガティブ値を受け入れます。これはヒューマノイドの Humanoid.Health を増加させます。しかし、これは存在しない場合にのみ効果があります。ForceField

フォースフィールドはどのようにタケダメージから保護する

A は、次の条件のいずれかに該当する場合、 によって保護されると考えられます:

To do damage to a Humanoid irrespective of any ForceFields present, set Humanoid.Health 直接。

For more information on how ForceFields 保護 Humanoids する方法については、ForceField ページを参照してください。

パラメータ

amount: number

ダメージ、または Humanoid.Health から控除される金額。

既定値: ""

戻り値

()

コードサンプル

Damaging a Humanoid

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid:TakeDamage(99)

UnequipTools

()

このメソッドは、現在 Tool に装備されているすべての Humanoid を解除します

装備されていない Tool は、Backpack に関連する Player となり、Humanoid と結合します。

Tool が装備されていない場合、このメソッドは何もしません。

NPC (ノンプレイヤーキャラクター) によって が装備できるものの、この方法は、対応する でのみ機能します。これは、装備されていない Backpack を親にするために Tool オブジェクトが必要だからです。

参照してください:


戻り値

()

コードサンプル

Unequip Tool Keybind

local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local player = Players.LocalPlayer
ContextActionService:BindAction("unequipTools", function(_, userInputState)
if userInputState == Enum.UserInputState.Begin then
if player.Character then
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:UnequipTools()
end
end
end
end, false, Enum.KeyCode.U)

ApplyDescription

()
イールド

この降伏方法により、キャラクターの外見が HumanoidDescription に送信されたものと一致します。パスされた HumanoidDescription のコピーが HumanoidDescription としてキャッシュされ、Humanoid になります。

このメソッドは、キャラクターの外観を変更するためにのみこのメソッドが使用され、呼び出し間で他の手段を介して変更は行われないと仮定して最適化されます。呼び出しの間にキャラクターに変更が行われた場合、このメソッドはキャラクターを正確に反映しない可能性があります。if changes are made to the character between calls, then this method may not make the character reflect the passed in HumanoidDescription accurately.キャラクターを更新する他の手段と一緒にこの方法を使用したい場合は、Humanoid:ApplyDescriptionReset() は常にキャラクターがパスされた HumanoidDescription を反映するようにします。

参照してください: See Also

パラメータ

humanoidDescription: HumanoidDescription

キャラクタを一致させたい HumanoidDescription インスタンス。

既定値: ""
assetTypeVerification: Enum.AssetTypeVerification
既定値: "Default"

戻り値

()

ApplyDescriptionReset

()
イールド

この降伏方法により、キャラクターの外観は、外部の変更後でも HumanoidDescription に送信されたものと一致します。パスされた HumanoidDescription のコピーが HumanoidDescription としてキャッシュされ、Humanoid になります。

このメソッドは、変更が HumanoidDescription システムを使用しないキャラクターに適用されている場合でも、キャラクターが HumanoidDescription システムを使用しないことを保証します (例えば、 ApplyDescriptionReset() または ApplyDescription() を使用しない)。これは、 が最適化され、キャラクターが を通じて変更された場合に不正確に適用される可能性があるのと対照しています。

パラメータ

humanoidDescription: HumanoidDescription

キャラクターを一致させたい HumanoidDescription インスタンス

既定値: ""
assetTypeVerification: Enum.AssetTypeVerification
既定値: "Default"

戻り値

()

PlayEmote

イールド

エモートが HumanoidDescription に emoteName が見つからないために再生できない場合、このメソッドはエラーを返します。メソッドは、リアクションが成功して再生されたことを示すために true を返します。

パラメータ

emoteName: string

プレイするエモートの名前。

既定値: ""

戻り値

成功して再生されました。

イベント

ApplyDescriptionFinished

パラメータ

description: HumanoidDescription

Climbing

Humanoid が上昇する速度が変更されたときに発火します。

Humanoids は、Parts または TrussParts で作られたはしごを登ることができます。

Humanoids 彼らの Humanoid.WalkSpeed の 70% で登る。

このイベントは、Humanoid がクライミングをやめると、速度 0 で常に発動しないことがあります。

参照してください:

パラメータ

speed: number

現在、Humanoid が登っている速度。


コードサンプル

Humanoid.Climbing

local Players = game:GetService("Players")
local function onCharacterClimbing(character, speed)
print(character.Name, "is climbing at a speed of", speed, "studs / second.")
end
local function onCharacterAdded(character)
character.Humanoid.Climbing:Connect(function(speed)
onCharacterClimbing(character, speed)
end)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

Died

このイベントは、Humanoid が死亡するとき、通常 Humanoid.Health が 0 に達するときに発動します。これは、彼らの頭をHumanoid.Torsoから切断するか、健康プロパティを直接設定することによって引き起こされる可能性があります。

このイベントは、HumanoidWorkspace の子孫である場合にのみ発動します。如果 Dead Enum.HumanoidStateType が無効になっている場合、発動しません。


コードサンプル

Humanoid.Died

local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local function onDied()
print(player.Name, "has died!")
end
humanoid.Died:Connect(onDied)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

FallingDown

落下イベントは、Humanoid が入り、FallingDown Enum.HumanoidStateType を離れると発動します。

The Humanoid は、GettingUp 状態が有効になった後、3秒で FallingDown 状態に入ります。これが発生すると、このイベントは 有効 の 値 で発射し、 は 有効 の 値 で発射します。

パラメータ

active: boolean

HumanoidFallingDownEnum.HumanoidStateType に入っているか、退出しているかを述べます。


FreeFalling

このイベントは、HumanoidFreefall Enum.HumanoidStateType に入るか、退出するときに発動します。

アクティブな パラメータ は、Humanoid が状態 Freefall に入っているか、退出しているかを表します。

状態 が一般的に終了するときは、 が地面に到達すると、このイベントは、状態が変更されている間、 有効 と等しい false で発射する可能性があります。このため、Humanoid.StateChanged を使用し、Landed が着陸したときに作動する Humanoid 状態を聞く必要があります。

パラメータ

active: boolean

HumanoidFreefall Enum.HumanoidStateType に入っているか退出しているか。


GettingUp

このイベントは、HumanoidEnum.HumanoidStateType.GettingUp 状態に入るか、Humanoid 状態から退出するとき、FallingDown (3秒) または Ragdoll (1秒) 状態に入るときに発動します。

When a Humanoid が再起動を試みると、このイベントは最初に active パラメータの true で再起動し、すぐに active パラメータの false で再起動します。

Humanoid を強制して落下させるには、Humanoid:ChangeState() 関数を使用して Enum.HumanoidStateType.FallingDown

パラメータ

active: boolean

HumanoidGettingUp Enum.HumanoidStateType に入っているか退出しているか。


HealthChanged

このイベントは、Humanoid.Health が変更されると発動します。しかし、健康が Humanoid.MaxHealth と同じまたはそれ以上の値から増加している場合、発射しません。

When Humanoid.Health がゼロに達すると、Humanoid が死に、Humanoid.Died イベントが発動します。このイベントはゼロの値で発動します。

パラメータ

health: number

新しい値の Humanoid.Health


コードサンプル

Humanoid.HealthChanged

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local currentHealth = humanoid.Health
local function onHealthChanged(health)
local change = math.abs(currentHealth - health)
print("The humanoid's health", (currentHealth > health and "decreased by" or "increased by"), change)
currentHealth = health
end
humanoid.HealthChanged:Connect(onHealthChanged)
end
player.CharacterAdded:Connect(onCharacterAdded)
Health Bar

local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Paste script into a LocalScript that is
-- parented to a Frame within a Frame
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- black
-- This function is called when the humanoid's health changes
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- Change the size of the inner bar
frame.Size = UDim2.new(percent, 0, 1, 0)
-- Change the color of the health bar
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- black
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- yellow
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- green
end
end
-- This function runs is called the player spawns in
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- Pattern: update once now, then any time the health changes
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- Connect our spawn listener; call it if already spawned
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end

Jumping

このイベントは、Humanoid が入り、Jumping Enum.HumanoidStateType を離れると発動します。

ジャンプが起こると、このイベントは、 パラメータの 後、 パラメータの で再び発射します。この2回目の発射は、Humanoid 着陸に一致しません;そのためには、Landed Enum.HumanoidStateType を使用して、Humanoid.StateChanged を聞きます。

Humanoid:SetStateEnabled() 関数を使用してジャンプを無効にすることができます。

パラメータ

active: boolean

HumanoidJumping Enum.HumanoidStateType に入っているか退出しているか。


MoveToFinished

このイベントは、Humanoid が目標を宣言した Humanoid.WalkToPoint および Humanoid.WalkToPart プロパティへ歩くのを終えたときに発動します。

Humanoid.WalkToPoint および Humanoid.WalkToPart プロパティは個別に設定するか、Humanoid:MoveTo() 関数を使用して設定できます。

Humanoid が 8秒以内に目標に到達すると、このイベントは 到達 として真実に戻ります。目標が 8秒以内に達成されない場合、Humanoid は歩行を停止し、到達 は偽になります。この期限切れは、期限切れ期間内に再び Humanoid:MoveTo() を呼び出すことでリセットできます。

パラメータ

reached: boolean

ゴールに到達したかどうかを示す Humanoid のブールン値。 は、Humanoid が目標に到達した場合、 は、目標に到達できなかった場合にタイムアウトしました。


コードサンプル

Humanoid MoveTo Without Time out

local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- listen for the humanoid reaching its target
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- start walking
humanoid:MoveTo(targetPoint)
-- execute on a new thread so as to not yield function
task.spawn(function()
while not targetReached do
-- does the humanoid still exist?
if not (humanoid and humanoid.Parent) then
break
end
-- has the target changed?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresh the timeout
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- disconnect the connection if it is still connected
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "Destination reached!") or "Failed to reach destination!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)

PlatformStanding

このイベントは、HumanoidPlatformStanding Enum.HumanoidStateType に入るか、退出するときに発動します。

HumanoidPlatformStanding 状態にある間、Humanoid.PlatformStand プロパティは true になります。

While Humanoid.PlatformStandtrue に設定されている間、Humanoid は移動できません。詳細は、Humanoid.PlatformStand のページを参照してください。

プラットフォームスタンド Enum.HumanoidStateType は、今は使用できない Platform 部分と関連していました。それにもかかわらず、開発者はまだ使用できます。

パラメータ

active: boolean

HumanoidPlatformStanding Enum.HumanoidStateType に入っているか退出しているか。


Ragdoll

このイベントは、HumanoidRagdoll Enum.HumanoidStateType に入るか、退出するときに発動します。

active パラメータには、入るか離れることを示す値 true または false が含まれます。

Humanoid:SetStateEnabled() を使用して、Ragdoll 状態に残るために GettingUp 状態を無効にします。

参照してください:

パラメータ

active: boolean

HumanoidRagdoll Enum.HumanoidStateType に入っているか退出しているか。


Running

このイベントは、Humanoid が実行されている速度が変更されたときに発動します。

Humanoids カバーを実行している間、平均して秒ごとに Humanoid.WalkSpeed 個のスタッドを処理します。

When the Humanoid がこのイベントの実行を停止すると、速度 0 で発射します。

参照してください:

パラメータ

speed: number

Humanoid が実行されている速度。


コードサンプル

Humanoid Running

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local function onRunning(speed: number)
if speed > 0 then
print(`{localPlayer.Name} is running`)
else
print(`{localPlayer.Name} has stopped`)
end
end
humanoid.Running:Connect(function(speed: number)
onRunning(speed)
end)

Seated

このイベントは、Humanoid が座っていたり、Seat から起きたり、VehicleSeat から起きたりすると発動します。

キャラクターが座席に接触すると、座席に付属し、座っているアニメーションが再生されます。この情報については、Seatを参照してください。

  • キャラクターが座っている場合、active パラメータは true であり、currentSeatPart は現在座っている座席です。
  • キャラクターが座席から起きた場合、active パラメータは 偽り になり、currentSeatPartnil になります。

参照してください:

  • Humanoid.Sit , ヒューマノイドが現在座っているかどうかを示す
  • Humanoid.SeatPart , ヒューマノイドが現在座っているシートを示す, ある場合は。

パラメータ

active: boolean

Humanoid が座っている場合は、真です。

currentSeatPart: BasePart

Humanoid に座っている場合、座っている席に座ります。


コードサンプル

Finding a Player's Seat

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local function onSeated(isSeated, seat)
if isSeated then
print("I'm now sitting on: " .. seat.Name .. "!")
else
print("I'm not sitting on anything")
end
end
humanoid.Seated:Connect(onSeated)

StateChanged

このイベントは、Humanoid の状態が変更されたときに発動します。

「待機」ヒューマノイド状態は存在しないため、代わりに Humanoid.Running イベントを使用するか、RootPart 部分の Velocity を聴いて、Humanoid が静止しているときに作業する必要があります。

参照してください: See Also

パラメータ

ヒューマノイドの前の状入力タイプ。

ヒューマノイドの現在の状入力タイプ。


コードサンプル

Jumping Particles

local character = script.Parent
local primaryPart = character.PrimaryPart
-- create particles
local particles = Instance.new("ParticleEmitter")
particles.Size = NumberSequence.new(1)
particles.Transparency = NumberSequence.new(0, 1)
particles.Acceleration = Vector3.new(0, -10, 0)
particles.Lifetime = NumberRange.new(1)
particles.Rate = 20
particles.EmissionDirection = Enum.NormalId.Back
particles.Enabled = false
particles.Parent = primaryPart
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
-- listen to humanoid state
local function onStateChanged(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not isJumping then
isJumping = true
particles.Enabled = true
end
elseif newState == Enum.HumanoidStateType.Landed then
if isJumping then
isJumping = false
particles.Enabled = false
end
end
end
humanoid.StateChanged:Connect(onStateChanged)
Jump Cooldown

local character = script.Parent
local JUMP_DEBOUNCE = 1
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not isJumping then
isJumping = true
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
elseif newState == Enum.HumanoidStateType.Landed then
if isJumping then
isJumping = false
task.wait(JUMP_DEBOUNCE)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
end)

StateEnabledChanged

状態変更イベントは、Humanoid:SetStateEnabled()Humanoid で呼び出されたときに発動します。

パラメータには、この状態が有効になっているかどうかを示す bool とともに、問題の Enum.HumanoidStateType が含まれます。

参照してください:

パラメータ

有効な状態が変更された Enum.HumanoidStateType に対する。

isEnabled: boolean

状態が有効になっている場合は true です。


コードサンプル

Humanoid State Change Detector

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local function onStateEnabledChanged(state, enabled)
if enabled then
print(state.Name .. " has been enabled")
else
print(state.Name .. " has been disabled")
end
end
humanoid.StateEnabledChanged:Connect(onStateEnabledChanged)

Strafing

このイベントは、Humanoid がストレイフを行っているときに発動しないため、開発者によって使用されるべきではありません

このイベントは、HumanoidStrafingNoPhysics Enum.HumanoidStateType に入るか、退出するときに発動します。

When the HumanoidStrafingNoPhysics 状態に入ると、このイベントは 有効 パラメータの true で発射します。イベントは、有効 と等しいときに再び発動しますが、Humanoid が状態を離れるときに、StrafingNoPhysics が等しくなります。

このイベントは StrafingNoPhysics Humanoid 状態と関連しており、 **** がHumanoid が向いている方向と平行して移動しているときに発射しません。この状態は現在使用されていません、Humanoid:ChangeState() を使用して設定すると、状態は RunningNoPhysics に戻ります。

パラメータ

active: boolean

HumanoidStrafingNoPhysics Enum.HumanoidStateType に入っているか退出しているか。


Swimming

このイベントは、Humanoid が水中で泳いでいる速度が変化するときに発動します。このイベントは、水中で泳いでいる Terrain の速度が変化するときに発動します。

Humanoids 彼らの Humanoid.WalkSpeed の 87.5% で泳ぐ。

このイベントは、Humanoid が泳ぐのをやめたとき、常に速度 0 で発動するわけではありません。

参照してください:

パラメータ

speed: number

Humanoid が現在泳いでいる速度。


Touched

このイベントは、ヒューマノイドの腕の 1つが他の BasePart と接触すると発動します。肢が触れている BasePart は、肢自体とともに与えられます。

このイベントは、Humanoid に属する肢が自分自身と接触すると発動しません。

代替

Humanoid.Touched イベントは便利ですが、ニーズにより良い代替があるかどうかを検討する必要があります。

  • ほとんどの場合、BasePart.Touched イベントではなく、BaseParts の関心のために、Humanoid.Touched イベントを接続することをお勧めします。これは、ヒューマノイドが移動するときに連続して発射されるためです。たとえば、ドッジボールゲームでは、ボールに対して Touched イベントを接続するのがより実用的であり、Humanoid.Touched を使用するよりも効率的です。
  • Humanoid が地面に着陸したときに作業を試みると、Humanoid.StateChanged イベントがより適しています。代わりに、Humanoid.FloorMaterial をチェックして、ヒューマノイドが非空気材料の上に立っているかどうかを確認できます。

ノート

パラメータ

touchingPart: BasePart

接触したのは、BasePartHumanoid です。

humanoidPart: BasePart

触れた Humanoid の肢。


コードサンプル

Midas Touch

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local partInfo = {}
local debounce = false
local function onHumanoidTouched(hit, _limb)
if debounce then
return
end
if not hit.CanCollide or hit.Transparency ~= 0 then
return
end
if not partInfo[hit] then
partInfo[hit] = {
BrickColor = hit.BrickColor,
Material = hit.Material,
}
hit.BrickColor = BrickColor.new("Gold")
hit.Material = Enum.Material.Ice
debounce = true
task.wait(0.2)
debounce = false
end
end
local touchedConnection = humanoid.Touched:Connect(onHumanoidTouched)
local function onHumanoidDied()
if touchedConnection then
touchedConnection:Disconnect()
end
-- undo all of the gold
for part, info in pairs(partInfo) do
if part and part.Parent then
part.BrickColor = info.BrickColor
part.Material = info.Material
end
end
end
humanoid.Died:Connect(onHumanoidDied)