ヒューマノイド

ヒューマノイドのメソッドとプロパティ

TakeDamageヒューマノイドのヘルスを指定された量だけ減らします。
MoveToヒューマノイドを指定された場所やパーツに歩かせます。
GetState現在のヒューマノイドの状態をEnum.HumanoidStateTypeとして返します。
ChangeStateヒューマノイドを指定された状態に変更します。
RemoveAccessoriesヒューマノイドの親モデルが装着しているすべてのアクセサリーを取り外します。
ReplaceBodyPartR15R15の身体パーツを別のパーツに置き換えます。
SetStateEnabledヒューマノイドの指定された状態を有効または無効にします。
UnequipToolsヒューマノイドが現在装備しているツールを外します。
ApplyDescriptionヒューマノイドにHumanoidDescriptionを適用します。
ApplyDescriptionResetヒューマノイドにHumanoidDescriptionを適用し、すべての変更をリセットします。
PlayEmote有効な場合、指定されたエモートを再生します。
Moveヒューマノイドを指定された方向に移動させます。
GetMoveVelocityヒューマノイドの現在の移動速度を返します。
EquipTool指定されたツールをヒューマノイドに装備させます。
Healthヒューマノイドの現在のヘルスを表します。
MaxHealthヒューマノイドが持つことができる最大ヘルスを表します。
WalkSpeedヒューマノイドが歩く速度を決定します。
JumpPowerヒューマノイドのジャンプ力を制御します。
HipHeightヒューマノイドの腰が地面からの高さを表します。
AutoRotateヒューマノイドが移動方向に自動的に向きを変えるかどうかを決定します。
BreakJointsOnDeathヒューマノイドが死んだときにジョイントが切れるかどうかを制御します。
CameraOffsetヒューマノイドに対するカメラのオフセット。
FloorMaterialヒューマノイドが立っている床の材質を示します。
NameDisplayDistanceヒューマノイドの名前が表示される距離。
NameOcclusion名前プレートの表示方法を決定します。
Sitヒューマノイドが座っているかどうかを示します。
TargetPointヒューマノイドが向かっている地点。

ヒューマノイドのヘルス例

local Players = game:GetService("Players")

local function onPlayerAdded(player)
	-- Wait for the player's character to load
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:WaitForChild("Humanoid")

	-- Example: Setting Health
	print("Current Health:", humanoid.Health)
	humanoid.Health = 50 -- Set health to 50
	print("New Health:", humanoid.Health)


	-- Example: Adding Health
	print("Current Health:", humanoid.Health)
	local healthToAdd = 20
	humanoid.Health = math.min(humanoid.Health + healthToAdd, humanoid.MaxHealth) 
	print("Health after adding health:", humanoid.Health)

	-- Example: Checking if Humanoid is Dead
	humanoid.Died:Connect(function()
		print("Humanoid has died!")
	end)

	-- Example: Changing MaxHealth
	print("Current MaxHealth:", humanoid.MaxHealth)
	humanoid.MaxHealth = 200 -- Set MaxHealth to 200
	print("New MaxHealth:", humanoid.MaxHealth)

	-- Example: Setting Health to MaxHealth
	humanoid.Health = humanoid.MaxHealth
	print("Health set to MaxHealth:", humanoid.Health)
	
	-- Example: Taking Damage
	print("Current Health:", humanoid.Health)
	humanoid.Health = humanoid.Health - 300 -- Directly reduce health by 300
	print("Health after taking damage:", humanoid.Health)

end

-- Connect the function to the PlayerAdded event
Players.PlayerAdded:Connect(onPlayerAdded)
Image 1
Roblox Studio

ヒューマノイドのアニメーション例

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

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

-- Animation setup
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://131036267483527" -- Replace with your animation asset ID

-- Load the animation onto the humanoid
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack.Looped = false -- Ensure the animation does not loop by default

-- Function to play the animation
local function playAnimation()
	print("playAnimation")
	animationTrack:Play()
end

-- Function to stop the animation
local function stopAnimation()
	print("stopAnimation")
	animationTrack:Stop()
end

-- Function to loop the animation
local function loopAnimation(loopCount)
	animationTrack.Looped = true
	animationTrack:Play()
	print("loopAnimation")

	-- Stop looping after the specified count
	delay(loopCount * animationTrack.Length, function()
		animationTrack.Looped = false
		stopAnimation()
		print("loopAnimation stopped")
	end)
end

-- Detect when "P", "T", or "L" is pressed and trigger the appropriate function
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.P and not gameProcessedEvent then
		print("pressed P")
		playAnimation()
	end
	if input.KeyCode == Enum.KeyCode.T and not gameProcessedEvent then
		print("pressed T")
		stopAnimation()
	end
	if input.KeyCode == Enum.KeyCode.L and not gameProcessedEvent then
		print("pressed L")
		loopAnimation(3)
	end
end)
Image 1
Roblox Studio

ヒューマノイドの移動例

-- Function to make the humanoid walk to a specific point
local function walkToPoint(point)
    humanoid:MoveTo(point)
end

-- Function to make the humanoid move in a specific direction
local function moveInDirection(direction)
    humanoid:Move(direction)
end

-- Function to stop the humanoid's movement
local function stopMovement()
    humanoid:Move(Vector3.new(0, 0, 0))
end

-- Example usage
local targetPoint = Vector3.new(10, 0, 10) -- Define a target point
walkToPoint(targetPoint) -- Make the humanoid walk to the target point

-- After a delay, make the humanoid move in a specific direction
wait(2)
local direction = Vector3.new(1, 0, 0) -- Define a direction
moveInDirection(direction)

-- After a delay, stop the humanoid's movement
wait(2)
stopMovement()
Image 1
Roblox Studio
  • Humanoid:MoveToを使用すると、ヒューマノイドは適切な歩行または走行アニメーションを自動的に再生します。
  • このメソッドは、ヒューマノイドの内部状態を歩行または走行に設定し、ターゲットに到達した後、または移動が中断された場合に待機状態に戻します。
  • ヒューマノイドが目的地に到達したとき、または特定のタイムアウト期間内に到達できなかったときにMoveToFinishedイベントが発生します。

ヒューマノイドのイベント例

local Players = game:GetService("Players")

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

-- Function to handle when the humanoid finishes moving to a point
humanoid.MoveToFinished:Connect(function(reached)
    if reached then
        print("Humanoid reached the destination")
    else
        print("Humanoid did not reach the destination")
    end
end)

-- Example function stubs for each event
local function onDied()
    print("Humanoid died")
end

local function onRunning(speed)
    print("Humanoid is running at speed:", speed)
end

local function onJumping()
    print("Humanoid is jumping")
end

local function onClimbing()
    print("Humanoid is climbing")
end

local function onGettingUp()
    print("Humanoid is getting up")
end

local function onFreeFalling()
    print("Humanoid is in free fall")
end

local function onFallingDown()
    print("Humanoid is falling down")
end

local function onSeated()
    print("Humanoid is seated")
end

local function onPlatformStanding()
    print("Humanoid is platform standing")
end

local function onSwimming()
    print("Humanoid is swimming")
end

-- Connect the functions to the respective humanoid events
humanoid.Died:Connect(onDied)
humanoid.Running:Connect(onRunning)
humanoid.Jumping:Connect(onJumping)
humanoid.Climbing:Connect(onClimbing)
humanoid.GettingUp:Connect(onGettingUp)
humanoid.FreeFalling:Connect(onFreeFalling)
humanoid.FallingDown:Connect(onFallingDown)
humanoid.Seated:Connect(onSeated)
humanoid.PlatformStanding:Connect(onPlatformStanding)
humanoid.Swimming:Connect(onSwimming)
Image 1
Roblox Studio

このチュートリアルがお役に立ちましたら、私の仕事をサポートするためにコーヒーをおごっていただけると嬉しいです。

ご支援、誠にありがとうございます!

コーヒーをおごる