휴머노이드는 모델에 캐릭터의 기능을 제공하는 특수 개체입니다.물리적으로 로블록스 경험의 다양한 구성 요소를 돌아다니고 상호작용할 수 있는 능력을 갖춘 모델을 부여합니다.인간형은 항상 Model 내에서 부모로 지정되며, 모델은 BasePart 및 Motor6D의 조합이 될 것으로 예상됩니다; 조립의 루트 부분은 HumanoidRootPart로 명명될 것으로 예상됩니다.또한 부품 이름 Head 이 직접 또는 간접적으로 캐릭터의 몸통 부분에 연결되기를 기대합니다.기본적으로 Roblox에서 제공하는 공식 유형의 캐릭터 리그는 각각 자체 규칙 집합이 있습니다:
R6
- 사지를 위해 6개의 부품을 사용하는 기본 캐릭터 리그.
- Head 부분은 Torso라는 부품에 연결되어야 하며, 그렇지 않으면 휴머노이드가 즉시 사망합니다.
- 신체 부위 모양은 CharacterMesh 개체를 사용하여 적용됩니다.
- Humanoid.LeftLeg 및 Humanoid.RightLeg와 같은 특정 속성은 R6와만 작동합니다.
R15
- R6보다 더 복잡하지만 훨씬 유연하고 강력합니다.
- 사지에는 15개의 부품을 사용합니다.
- Head 부품은 UpperTorso 이름의 부품에 연결되거나 휴머노이드가 즉시 사망합니다.
- 신체 부위 모양은 직접 조립되어야 합니다.
- Humanoid 내부에서 특수 NumberValue 개체를 사용하여 동적으로 크기를 조정할 수 있습니다.
- 휴머노이드는 각 사지 내에서 명명된 개체를 자동으로 생성합니다.
- Humanoid 내에 NumberValue가 부모로 지정되고 팔로잉중 하나의 이름으로 명명되면 스케일링 기능을 제어하는 데 사용됩니다.
- 바디 깊이 비율
- 바디 높이 스케일
- 바디 너비 비율
- 헤드스케일
코드 샘플
This LocalScript makes the camera bobble as the player's character walks around, utilizing both the Humanoid's CameraOffset and MoveDirection. It should be parented inside of the StarterCharacterScripts so that it is distributed into a player's character as expected.
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)
요약
속성
모바일 기기플레이어로서 캐릭터가 장애물을 치면 자동으로 점프할지 여부를 설정합니다.
자동 회전은 휴머노이드가 이동하는 방향으로 자동으로 회전할지 여부를 설정합니다.
활성화되면 AutomaticScalingEnabled는 휴머노이드의 자식 규모 값이 변경되는 응답으로 캐릭터의 크기가 변경되도록 합니다.
인간의 관절이 Enum.HumanoidStateType.Dead 상태에서 부서지는지 여부를 결정합니다.
카메라의 주제 위치에 적용된 오프셋으로, 카메라 주제가 이 휴머노이드로 설정되었을 때.
인간형의 이름과 체력 표시의 거리 동작을 제어합니다.
상단에 표시되는 휴머노이드의 텍스트를 설정합니다.
현재 Enum.Material에 서 있는 Humanoid에 대해 설명합니다.Humanoid 가 아무것도 서 있지 않으면 이 속성의 값은 공기 가 됩니다.
범위 [0, ]에서 현재 상태의 휴머노이드를 설명합니다.
DisplayDistanceType 속성과 함께 사용하여 인간형의 체력 바가 볼 수 있는 거리를 제어합니다.
인간의 체력 바가 표시될 수 있는 시기를 제어합니다.
Humanoid.RootPart 가 있어야 하는 지상에서의 거리를 결정합니다.
만약 true , Humanoid 는 위쪽으로 힘을 가지고 점프합니다.
Humanoid 점프하는 높이를 제어합니다.
점프할 때 Humanoid에 얼마나 많은 상향 힘이 적용되는지 결정합니다.
인간형의 최대값 Health .
인간형이 미끄러지지 않고 걸을 수 있는 최대 경사 각도.
Humanoid가 걷고 있는 방향을 설명합니다.
Humanoid.DisplayDistanceType 속성과 함께 사용하여 인간형의 이름이 보일 수 있는 거리를 제어합니다.
인간형의 이름과 체력바가 벽이나 다른 개체 뒤에서 볼 수 있는지 여부를 제어합니다.
현재 Humanoid가 Enum.HumanoidStateType.PlatformStanding 상태에 있는지 여부를 결정합니다.
개발자가 목 을 제거하거나 잠시 연결을 끊어도 플레이어가 죽는 행동을 비활성화할 수 있도록 허용합니다.
이 Humanoid 가 레거시 R6 캐릭터 리그나 새로운 R15 캐릭터 리그를 사용하는지 여부를 설명합니다.
인간형의 HumanoidRootPart 개체에 대한 참조.
현재 Humanoid에 앉아 있는 자리에 대한 참조, 있는 경우.
현재 앉아 있는지 여부를 Humanoid 설명합니다.
3D 위치를 설명하며, 를 사용하여 세계에서 마지막으로 클릭한 를 제어합니다.
JumpHeight(거짓) 또는 Humanoid.JumpPower(참) 속성이 사용되는지 여부를 결정합니다.
인간형의 최대 이동 속도를 초당 스터드 수로 설명합니다.
인간형이 도달하려고 하는 부분의 참조. 위치
Humanoid:MoveTo()에 대한 호출 후 인간형이 도달하려는 위치.
메서드
지정된 Accessory를 인간형의 부모에 연결합니다.
인간의 캐릭터에 있는 개체를 연결하여 Motor6D 조인의 트리를 조립하고 Attachment 개체를 함께 연결합니다.
를 설정하여 지정된 에 들어갑니다.
현재 인간형의 부모가 착용하고 있는 배열의 Accessory 개체를 반환합니다.
현재 모습을 설명하는 인간형의 캐시된 복사본을 반환합니다. HumanoidDescription which describes its current look.
이 메서드에 신체 부분을 전달하여 (신체 부분은 Humanoid의 형제이고 모델의 자식이어야 함) Enum.BodyPartR15 의 Part 를 얻습니다.
인간형의 현재 Enum.HumanoidStateType를 반환합니다.
Enum.HumanoidStateType``Class.Humanoid 활성화되었는지 여부를 반환합니다.
Humanoid 가 지정된 방향으로 걷도록 합니다.
Humanoid를 설정하여 지정된 위치로 걸어가려고 시도하게 하고 Humanoid.WalkToPoint 및 Humanoid.WalkToPart 속성을 설정하여 이동합니다.
인간형의 부모가 착용하는 모든 Accessory 개체를 제거합니다.
동적으로 인간형 신체 부분을 다른 부분으로 교체합니다.
지정된 Enum.HumanoidStateType 가 활성화되는지 여부를 설정합니다. Humanoid 에 대해.
보호되지 않는 경우 Humanoid.Health 의 Humanoid 를 지정된 수량 으로 줄이고, ForceField 에 의해 보호되지 않는 경우에는 그 값을 줄입니다.
- ApplyDescription(humanoidDescription : HumanoidDescription,assetTypeVerification : Enum.AssetTypeVerification):()
문자의 모양이 HumanoidDescription에 전달된 것과 일치하도록 합니다.
- ApplyDescriptionReset(humanoidDescription : HumanoidDescription,assetTypeVerification : Enum.AssetTypeVerification):()
외부 변경 후에도 문자의 모양이 HumanoidDescription에 일치하도록 만듭니다.
감정 표현을 재생하고 성공적으로 실행되었는지 여부를 반환합니다.
이벤트
Humanoid가 오르는 속도가 변경될 때 발화합니다.
Humanoid 가 죽을 때 화재를 발생시킵니다.
Humanoid 가 들어가거나 떠날 때 화재를 발생시킵니다. FallingDown``Enum.HumanoidStateType 에 들어갑니다.
Humanoid 가 들어가거나 떠날 때 화재를 발생시킵니다. Freefall``Enum.HumanoidStateType 에 들어갑니다.
Humanoid 가 들어가거나 떠날 때 화재를 발생시킵니다. GettingUp``Enum.HumanoidStateType 에 들어갑니다.
Humanoid.Health 또는 Humanoid.MaxHealth 발생하는 화재
Humanoid 가 들어가고 나가면 화재가 발생합니다 Jumping``Enum.HumanoidStateType .
가 목표로 선언된 곳으로 걸어가는 것을 완료하면 발생합니다.
Humanoid 가 들어가거나 떠날 때 화재를 발생시킵니다. PlatformStanding``Enum.HumanoidStateType 에 들어갑니다.
Humanoid 가 들어가거나 떠날 때 화재를 발생시킵니다. Ragdoll``Enum.HumanoidStateType 에 들어갑니다.
Humanoid가 실행되는 속도가 변경될 때 발생하는 화재.
Humanoid 또는 Seat 또는 VehicleSeat 에 앉아 있거나 일어날 때 발사됩니다.
상태가 Humanoid
Humanoid:SetStateEnabled()에서 Humanoid에 호출되면 화재가 발생합니다.
Humanoid 가 들어가거나 떠날 때 화재를 발생시킵니다. StrafingNoPhysics``Enum.HumanoidStateType 에 들어갑니다.
에서 수영하는 속도가 변경될 때 화재가 발생합니다.
인간형의 팔이 다른 것과 접촉할 때 발생합니다. BasePart .
속성
AutoJumpEnabled
AutoJumpEnabled는 Humanoid 가 걸어가는 장애물을 자동으로 뛰어넘으려는지 여부를 설정합니다.
현재 이 속성은 다음 조건이 참이 될 때만 작동합니다:
- 휴머노이드의 캐릭터 모델은 Player.Character 의 Player 입니다.
- 질문의 플레이어가 터치 제어사용하고 있습니다.
플레이어의 캐릭터가 생성되면 속성 값이 플레이어의 Player.AutoJumpEnabled 속성과 일치하고, 이는 차례로 StarterPlayer.AutoJumpEnabled 속성과 일치합니다.
코드 샘플
This code sample is meant for a TextButton. It allows the player to toggle the auto-jumping behavior while on a mobile device.
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
자동 회전 속성은 Humanoid가 이동하는 방향으로 자동으로 회전할지 여부를 설명합니다.진실로 설정되면 캐릭터 모델은 인간형이 주변을 걷는 동안 점차적으로 이동 방향을 향하게 됩니다.거짓으로 설정되면 문자 모델은 회전 힘이 HumanoidRootPart에 적용되지 않는 한 현재 회전에 고정됩니다.
캐릭터 모델이 플레이어의 캐릭터인 경우, 휴머노이드의 회전 행동은 사용자 게임 설정의 회전 유형 속성에 영향을 받습니다.
자동 회전 속성이 true로 설정되면 로테이트 유형 속성은 휴머노이드의 회전에 다음과 같은 영향을 줍니다.
<th>동작</th><th>컨텍스트</th></tr></thead><tbody><tr><td>이동 상대</td><td /><td /></tr><tr><td>카메라 상대</td><td>캐릭터가 카메라 방향으로 회전하여 면을 향합니다.</td><td>플레이어의 카메라가 1인칭으로 확대되거나 쉬프트락 모드에 있습니다.</td></tr></tbody>
회전 유형 |
---|
코드 샘플
This script adds the functionality of a button to a part, which switches the AutoRotate property of whoever touches it.
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
Humanoid에는 BodyDepthScale , BodyHeightScale , BodyProportionScale , BodyTypeScale , BodyWidthScale , HeadScale 을 포함한 6개의 자녀 크기 값이 있습니다.이러한 값을 변경하면 캐릭터의 신체 부위와 액세서리의 크기가 변경되지만, AutomaticScalingEnabled 가 참이면 그렇습니다.
CameraOffset
카메라Offset 속성은 카메라의 주제 위치에 대한 오프셋을 설정할 때 Camera.CameraSubject 가 이 Humanoid 로 설정되면 카메라의 주제 위치에 대한 오프셋을 지정합니다.
오프셋은 인간형의 HumanoidRootPart 방향에 대해 개체 공간에 적용됩니다.예를 들어, (0, 10, 0)의 오프셋 값은 플레이어의 카메라를 플레이어의 휴머노이드 위로 10스터드 이동시킵니다.
코드 샘플
This LocalScript makes the camera bobble as the player's character walks around, utilizing both the Humanoid's CameraOffset and MoveDirection. It should be parented inside of the StarterCharacterScripts so that it is distributed into a player's character as expected.
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)
DisplayDistanceType
표시 거리 유형 속성은 휴머노이드의 이름과 체력 표시의 거리 동작을 제어합니다.이 속성은 사용 가능한 세 가지 값을 가진 Enum.HumanoidDisplayDistanceType 열거형을 사용하여 설정됩니다. 각각 고유한 규칙 집합이 있습니다.
- Viewer 로 설정되면 휴머노이드는 자신의 NameDisplayDistance 및 HealthDisplayDistance 범위 내의 다른 휴머노이드의 이름/건강을 볼 수 있습니다.
- Subject로 설정되면 휴머노이드는 전체 제어 자신의 이름과 건강 표시를 통해 자신의 NameDisplayDistance 및 HealthDisplayDistance 값을 통해 수행합니다.
- None 로 설정되면 인간형의 이름과 체력 바가 어떤 상황에서도 나타나지 않습니다.
캐릭터 이름/상태 표시에 대한 자세한 가이드를 참조하십시오. 캐릭터 이름과 상태 표시줄의 모양을 제어하는 방법.
코드 샘플
This example demonstrates how to set a Humanoid's Humanoid.DisplayerDistanceType, Humanoid.HealthDisplayDistance, and Humanoid.NameDisplayDistance properties. These properties determine how a humanoid's healthbar and name are rendered for a player.
First, we change the DisplayDistanceType to Viewer using Enum.HumanoidDisplayDistanceType. When set to viewer, the humanoid's Name and healthbar will be displayed based on the distance settings of the humanoid viewing them.
Then, the humanoid's HealthDisplayDistance is set to 0. Setting the property to 0 hides the healthbar completely. It is not displayed at any distance.
Finally, the humanoid's NameDisplayDistance is set to 100. This means that the humanoid's name will be visible to other humanoid's within 100 studs.
This example should work as expected when placed inside a Script that is a child of the humanoid.
local humanoid = script.Parent
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
humanoid.HealthDisplayDistance = 0
humanoid.NameDisplayDistance = 100
DisplayName
DisplayName는 인간형의 이름 표시를 결정하는 속성입니다. 표시되는 경우.기본적으로 새로운 휴머노이드는 빈 문자열의 값을 가집니다.if DisplayName 가 빈 문자열인 경우, 휴머노이드의 이름 표시는 휴머노이드의 부모 이름 속성으로 기본값으로 설정됩니다.
플레이어 캐릭터 로드
플레이어가 자신의 캐릭터를 로드할 때, 자동으로 또는 LoadCharacter()를 사용하여 엔진에 의해 생성된 휴머노이드의 DisplayName 속성이 플레이어의 DisplayName 속성으로 설정됩니다.
스타터캐릭터와 스타터휴머노이드
명명된 이 에 인접되거나, 모델에 명명된 인간형이 존재하면 게임의 플레이어가 캐릭터를 로드할 때 DisplayName 속성이 존중됩니다.엔진은 Humanoid의 DisplayName 속성을 재정의하기 위해서는 플레이어의 DisplayName 속성이 비어 있는 경우에만 Humanoid.DisplayName 의 StarterHumanoid 가 비어 있는 문자열인지 확인해야 합니다.
EvaluateStateMachine
FloorMaterial
이는 현재 서 있는 것을 설명하는 읽기 전용 속성입니다 Enum.Material 는 Humanoid 입니다.일반 Parts 및 Terrain 복셀과 함께 작동합니다.
아래 코드 샘플은 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으로 설정됩니다.
속성을 직접 설정하는 대신 TakeDamage() 함수를 사용하여 Health에서 뺄 수 있습니다.
체력 재생
기본적으로 비활성 건강 재생 스크립트가 인간형에 자동으로 삽입됩니다.이로 인해 죽지 않은 플레이어 캐릭터가 1%의 MaxHealth마다 재생성됩니다.이 재생 행동을 비활성화하려면 공백의 Script 명명된 건강 을 StarterCharacterScripts 에 추가하십시오.
건강 바 표시
Health 가 MaxHealth 보다 작으면 경험 내에 건강 바가 표시됩니다.상태 바의 표시 동작은 HealthDisplayDistance 및 HealthDisplayType에 의존합니다.
캐릭터 이름/상태 표시에 대한 자세한 가이드를 참조하십시오. 캐릭터 이름과 상태 표시줄의 모양을 제어하는 방법.
사망
캐릭터의 체력 값이 0에 도달하면 Humanoid 자동으로 Enum.HumanoidStateType.Dead 상태로 전환됩니다.이 상태에서는 Health 가 0으로 잠겨 있지만, 죽은 휴머노이드의 Health 를 양의 비영도 값으로 설정하는 오류나 경고는 없습니다.
HealthDisplayDistance
이 속성은 인간형의 체력 바를 볼 수 있는 거리를 제어하기 위해 DisplayDistanceType 속성과 함께 사용되는 숫자입니다.
캐릭터 이름/상태 표시에 대한 자세한 가이드를 참조하십시오. 캐릭터 이름과 상태 표시줄의 모양을 제어하는 방법.
HealthDisplayType
이 속성은 인간형의 체력 표시줄이 표시될 수 있는 시기를 제어합니다.기본적으로 이 속성은 DisplayWhenDamaged 로 설정되어 있으며, 이는 휴머노이드의 Health 가 자신의 MaxHealth 보다 작을 때만 건강 바가 표시되도록 합니다.또한 체력 바가 항상 표시되도록 AlwaysOn 또는 표시되지 않도록 AlwaysOff로 설정할 수 있습니다.
이 속성은 특정 거리에서 건강 바가 사라지게 하는 데 책임이 있는 휴머노이드의 HealthDisplayDistance 속성과 독립적으로 작동합니다.if Humanoid.HealthDisplayType|HealthDisplayType 가 AlwaysOn 로 설정되어 있으면, 어떻게 HealthDisplayDistance 가 구성되었는지에 따라 여전히 사라질 것입니다.
캐릭터 이름/상태 표시에 대한 자세한 가이드를 참조하십시오. 캐릭터 이름과 상태 표시줄의 모양을 제어하는 방법.
HipHeight
인간형이 서있을 때 지상에서 떨어져야 하는 거리(스터드)를 결정합니다(RootPart).The RigType 영향은 이 속성의 동작 방식에 영향을 줍니다.
R15 리그의 경우, 적절한 허리 높이가 미리 설정되어 높이가 RootPart 올바른지 확인합니다.다리의 높이는 사용되지 않습니다.인간형의 전체 높이는 다음 수식으로 설명할 수 있습니다: The overall height of the humanoid can be described in the following formula:
Height = (0.5 * RootPart.Size.Y) + HipHeight
R6 리그의 경우, HipHeight 대신 상대 오프셋을 설명합니다. 인간형의 전체 높이는 다음 수식으로 설명할 수 있습니다:
Height = LeftLeg.Size.Y + (0.5 * RootPart.Size.Y) + HipHeight
Jump
만약 true , the Humanoid 점프는 값의 Humanoid.JumpPower 또는 높이의 Humanoid.JumpHeight 상향 힘으로 점프하며, 값의 Humanoid.UseJumpPower 에 따라 다릅니다.
JumpHeight
점프의 높이를 스터드 단위로 제어합니다 Humanoid 점프.이 속성의 시작 값은 기본값으로 7.2로 설정된 StarterPlayer.CharacterJumpHeight 값에 의해 결정됩니다.
이 속성을 0으로 설정하면 인간형이 점프하는 것을 효과적으로 방지할 수 있지만, 상태를 비활성화하여 점프를 비활성화하는 것이 좋습니다.
이 속성은 기본적으로 다른 경우에는 관련이 없으므로 속성 창에만 표시되며, Humanoid.UseJumpPower가 false 로 설정되어 있으면 사용되지 않습니다(대신 Humanoid.JumpPower가 사용됩니다).
JumpPower
점프할 때 Humanoid에 얼마나 많은 상향 힘이 적용되는지 결정합니다.이 속성의 시작 값은 기본값인 StarterPlayer.CharacterJumpPower 의 값으로 결정되며 0과 1000 사이에서 제한됩니다.점프는 중력에 의한 가속을 결정하는 Workspace.Gravity 속성에도 영향을 받습니다.
이 속성을 0으로 설정하면 인간형이 점프하는 것을 효과적으로 방지할 수 있지만, 상태를 비활성화하여 점프를 비활성화하는 것이 좋습니다.
이 속성은 기본적으로 다른 경우에는 관련이 없으므로 속성 창에만 표시되며, Humanoid.UseJumpPower가 true 로 설정되어 있지 않으면 사용되지 않습니다(대신 Humanoid.JumpHeight가 사용됩니다).
MaxHealth
인간형의 최대값 Health .
이 속성의 값은 Health 속성과 함께 기본 건강 표시줄 크기를 조정하는 데 사용됩니다.인간형의 가 도달하면 건강 바가 표시되지 않을 수 있습니다, 해당 속성에 따라.
MaxSlopeAngle
이 속성은 인간형이 오르기수 있는 최대 경사 각도를 결정합니다.경사의 각도가 인간형의 MaxSlopeAngle보다 크면 경사로를 내려갑니다.
캐릭터가 생성될 때, 이 속성은 StarterPlayer.CharacterMaxSlopeAngle의 값에 따라 설정됩니다.
이 속성의 값은 0°와 89° 사이의 값으로 제한됩니다.기본값은 89°이므로 인간형은 기본적으로 원하는 경사면을 오를 수 있습니다.
코드 샘플
The example below demonstrates the effect of the MaxSlopAngle property by limiting the maximum slope the Players.LocalPlayer can walk up to 30°. The local player will slide down any slope greater than 30°.
This code below works as expected when placed in a LocalScript.
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:wait()
local h = char:FindFirstChild("Humanoid")
h.MaxSlopeAngle = 30
MoveDirection
이동 방향 은 유닛 벡터 또는 길이가 0인 벡터로 걷고 있는 방향을 설명하는 읽기 전용 속성입니다.방향은 세계 공간에서 설명됩니다.
이 속성이 읽기 전용이기 때문에 Script 또는 LocalScript로 설정할 수 없습니다.
코드 샘플
This LocalScript makes the camera bobble as the player's character walks around, utilizing both the Humanoid's CameraOffset and MoveDirection. It should be parented inside of the StarterCharacterScripts so that it is distributed into a player's character as expected.
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에 적용됩니다.
캐릭터 이름/상태 표시에 대한 자세한 가이드를 참조하십시오. 캐릭터 이름과 상태 표시줄의 모양을 제어하는 방법.
코드 샘플
In the below example, Player|Players will not be able to see each other's Player.Character names when they are obscured behind BasePart|BaseParts.
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
현재 Humanoid가 Enum.HumanoidStateType.PlatformStanding 상태에 있는지 여부를 결정합니다.참이면 휴머노이드는 자유낙하 상태에 있으며 이동할 수 없습니다.이 상태는 점프가 인간형을 상태에서 해제하지 않는다는 점을 제외하고 앉는 것과 비슷합니다.
RequiresNeck
개발자가 목 을 제거하거나 잠시 연결을 끊어도 플레이어가 죽는 행동을 비활성화할 수 있도록 허용합니다.이 속성은 기본적으로 true로 설정됩니다.
RigType
RigType 은 레거시 R6 캐릭터 리그나 최신 R15 캐릭터 리그를 사용하는지 여부를 설명합니다.
R6 리그는 6개의 가시적 Parts 를 사용하고 R15 리그는 15개의 가시적 Parts 을 사용합니다.R15 리그는 R6 리그보다 더 많은 관절을 가지고 있으므로 애니메이션될 때 훨씬 더 다재다능합니다.
이 속성이 올바르게 설정되지 않으면 Humanoid 가 올바르게 작동하지 않습니다.예를 들어, R15 휴머노이드의 리그 유형 이 R6로 설정되면, 는 호출된 토소 에 연결된 몸 이 없기 때문에 죽을 것입니다.
RootPart
인간의 참조 HumanoidRootPart 개체, 3D 세계를 통해 인간의 이동을 제어하는 Humanoid의 루트 드라이빙 부분.이 부분은 보통 보이지 않습니다.
R15 캐릭터의 경우, Model.PrimaryPart 모델의 Player.Character 는 HumanoidRootPart 로 설정됩니다.
R6 문자의 경우, Model.PrimaryPart 는 Head 부분으로 설정됩니다.
SeatPart
SeatPart는 현재 Humanoid에 앉아 있는 의자에 대한 참조이며, 필요한 경우 있습니다.이 속성의 값은 Seat 또는 VehicleSeat 일 수 있습니다.Humanoid가 현재 좌석에 앉아 있지 않은 경우 nil이 됩니다.
참고:
- 현재 Humanoid에 앉아 있는지 여부를 설명하는 부울에 대해서는 참조하십시오 Humanoid.Sit
Sit
Sit 속성은 현재 Humanoid가 앉아 있는지 여부를 나타내는 부울입니다.Humanoids 이 속성의 값을 참으로 설정하여 앉아있는 상태로 강제할 수 있습니다.앉은 상태에서 Humanoid 가 의자에 연결되지 않으면 다리에 충돌하지 않고 넘어집니다.A Humanoid 는 점프하여 앉은 상태에서 탈출할 수 있습니다.
참고:
- Humanoid가 Humanoid.Seated 이벤트에 연결하여 앉았을 때를 감지할 수 있습니다.
TargetPoint
사용하지 마십시오 이 속성은 완전히 중단된 실험적 모드가 활성화된 상태에서만 작동합니다.
이 속성은 공간에서 3D 위치를 설명하며, Player에서 마지막으로 클릭한 이 Humanoid에 장착된 Tool으로 제어합니다.
이 속성은 주로 클래식 도구가 도구를 활성화할 때 인간형이 타겟으로 삼는 것을 결정하는 데 사용됩니다.NPC에 클래식 로켓 발사기를 제공하고, 타겟 포인트 를 설정하고 도구의 Tool:Activate() NPC가 목표 지점에서 로켓을 발사할 수 있습니다.
UseJumpPower
캐릭터가 생성되면 이 속성은 기본값인 StarterPlayer.CharacterUseJumpPower에 따라 설정됩니다.
점프할 때, 이 값을 true로 설정하면 로봇이 그 높이로 점프하도록 보장하는 Humanoid.JumpHeight 값이 사용됩니다.이를 false로 설정하면 Humanoid.JumpPower 값이 사용되어 상향 힘을 적용합니다.
WalkSpeed
이 속성은 얼마나 빨리 Humanoid가 스터드당 초당 걸을 수 있는지 설명합니다.기본값은 StarterPlayer.CharacterWalkSpeed (16)이며, 플레이어 캐릭터가 매초 어떤 방향으로든 16스터드를 걷기수 있음을 의미합니다.
노트
WalkToPart
WalkToPart는 Humanoid가 도달하려는 부품에 대한 참조입니다.이 속성은 일반적으로 부품이 Humanoid의 Humanoid:MoveTo() 함수의 2번째 인수로 전달될 때 설정됩니다.
WalkToPart가 설정되고 인간형이 부품에 액세스하려고 노력하면 부품의 위치가 되는 벡터3 목표와 부품 회전에 관련된 개체 공간에서 번역된 Humanoid.WalkToPoint가 계속 업데이트됩니다.
Luau에서 다음과 같이 설명할 수 있습니다.
goal = humanoid.WalkToPart.CFrame:pointToObjectSpace(humanoid.WalkToPoint)
주의 사항
- WalkToPart의 값을 설정하는 것만으로는 인간형이 부품을 따라 시작하도록 만드는 데 충분하지 않습니다.
- Humanoid는 WalkToPoint의 값이 변경될 때 목표에 도달하기 시작하도록 요청받습니다.
- 이는 미래에 변경될 수 있습니다.
- 휴머노이드의 도달 목표 상태는 목표에 도달하지 못하면 8초 후에 만료됩니다.
- 이렇게 하면 NPC가 Humanoid.MoveToFinished 발사를 기다리는 데 갇히지 않습니다.
- 이런 일이 발생하지 않도록 하려면 MoveTo를 반복적으로 호출하여 시간 제한이 계속 재설정되도록 해야 합니다.
WalkToPoint
WalkToPoint는 휴머노이드가 도달하려고 하는 공간의 3D 위치를 설명하며, 휴머노이드의 Humanoid:MoveTo() 함수에 의해 그렇게 하도록 요청받은 후에 그렇게 합니다.
인간형의 Humanoid.WalkToPart가 설정되면, 목표는 부품 위치와 회전에 관련된 WalkToPoint를 변환하여 설정됩니다.WalkToPart가 설정되지 않으면 휴머노이드는 WalkToPoint에서 지정한 3D 위치에 직접 도달하려고 시도합니다.
주의 사항
- WalkToPoint의 값이 변경되어야 휴머노이드가 그것을 향해 걷기 시작할 수 있습니다.
- 만약 당신이 인간형의 걸음을 0,0,0로 이동하고 싶다면, 인간형의 MoveTo 함수를 사용해야 합니다.
- 이는 미래에 변경될 수 있습니다.
- 휴머노이드의 도달 목표 상태는 목표에 도달하지 못하면 8초 후에 만료됩니다.
- 이렇게 하면 NPC가 Humanoid.MoveToFinished 발사를 기다리는 데 갇히지 않습니다.
- 이런 일이 발생하지 않도록 하려면 MoveTo를 반복적으로 호출하여 시간 제한이 계속 재설정되도록 해야 합니다.
코드 샘플
This code sample includes a function that avoids the 8 second timeout on Humanoid:MoveTo() by calling Humanoid:MoveTo() again before the timeout elapses. It also includes an optional andThen parameter where developers can pass a function to be called when the humanoid reaches its destination.
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를 휴머노이드의 부모에 연결합니다.
이 메서드가 호출되면, 인간형의 부모에서 동일한 이름을 가진 을 검색하여 캐릭터에 가 연결되고, 장신구핸들에서 동일한 이름을 가진 에 연결됩니다.하나가 발견되면, 처리 부분이 Attachment 사용하는 Weld 을 사용하여 부모에 연결되고, 접합이 구성되어 Attachments 동일한 공간을 차지합니다.
필요한 Attachment 을 찾을 수 없으면 Accessory 는 인간형의 부모에 계속 부모로 남지만 분리됩니다.
일반적으로 액세서리 접합은 서버에서 생성되지만, 특정 상황에서 클라이언트에서 생성될 수 있습니다.이러한 상황에서 클라이언트 측 호출 AddAccessory() 은 항상 원하는 동작을 생성하지 않을 수 있으며, BuildRigFromAttachments() 를 사용하여 예상 용접 작품강제할 수 있습니다.
매개 변수
반환
코드 샘플
This script generates the "Clockwork's Shades" Accessory from scratch, and then attaches it to the player's character using Humanoid.AddAccessory You should paste this code into a regular script, and then parent it inside of the StarterPlayer's StarterCharacterScripts folder.
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 재생에 필요합니다.
인간형의 RootPart 에서 시작하여 이 메서드는 Attachments 현재 부분의 이름이 RigAttachment 로 끝나는 모든 부모를 수집합니다.그런 다음 같은 이름을 가진 첨부 파일을 공유하는 문자에서 일치하는 첨부 파일을 검색합니다.이 두 부착물을 사용하여, 두 부착물과 관련된 부품과 부착물의 Motor6D 조인이 생성되며, 부착물의 CFrame 에 따라 생성됩니다.
Humanoid:BuildRigFromAttachments() 또한 문자를 확장하고 바디 색상을 설정합니다.
반환
코드 샘플
A Lua port of the Humanoid's BuildRigFromAttachments function, so that the recursive behavior of the function can be seen.
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)
A script that generates an R15 character from scratch using a package's assetId.
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의 기본 동작으로 인해 일부 상태가 설정되면 자동으로 변경됩니다. 예를 들어:
- 인간형이 물에 없을 때 상태를 Enum.HumanoidStateType.Swimming로 설정하면 자동으로 Enum.HumanoidStateType.GettingUp로 설정됩니다.
- 사용되지 않으므로 상태를 Enum.HumanoidStateType.PlatformStanding로 설정하면 휴머노이드 상태가 자동으로 Enum.HumanoidStateType.Running로 설정됩니다.
이 방법을 사용하여 상태 를 설정하려면 클라이언트가 에서 수행해야 하고 클라이언트는 네트워크 소유권 을 가져야 합니다.대신, 서버 측에서 Script 이 메서드를 호출할 수 있지만, 서버는 플레이어 캐릭터의 네트워크 소유권을 가져야 합니다.
특정 상태를 활성화하거나 비활성화하려면 Humanoid:SetStateEnabled() 를 참조하고, 현재 휴머노이드 상태를 가져오려면 Humanoid:GetState()를 참조하십시오.
매개 변수
The Enum.HumanoidStateType 는 Humanoid 가 수행해야 하는 것입니다.
반환
코드 샘플
This code, when placed inside a LocalScript in StarterPlayer.StarterCharacterScripts, will allow the player's character to perform a 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 를 장착합니다.
아래 예제에서는 에 도구를 장착하도록 '도구' 라는 이름의 도구를 장착시킬 것입니다.
local Players = game:GetService("Players")local Workspace = game:GetService("Workspace")local player = Players:FindFirstChildOfClass("Player")if player and player.Character thenlocal humanoid = player.Character:FindFirstChildWhichIsA("Humanoid")if humanoid thenlocal tool = Workspace:FindFirstChild("Tool")if tool thenhumanoid:EquipTool(tool)endendend
이 메서드가 호출되면 Humanoid 는 현재 장착 중인 모든 Tools 을 먼저 자동으로 장착 해제합니다.
그들이 장착되더라도, 에 대한 는 핸들이 없으면 작동하지 않으며, 이 메서드를 사용하여 장착하든 아니든 상관없이 마찬가지입니다.
참조하세요:
- 도구를 장착 해제하려면 Humanoid:UnequipTools()를 사용하십시오
매개 변수
반환
GetAccessories
이 메서드는 현재 인간형의 부모가 착용하고 있는 배열의 Accessory 개체를 반환합니다.모든 이러한 Accessory 개체가 연결되었는지 여부에 관계없이 포함됩니다.
에 개체가 없으면 빈 배열이 반환됩니다.
또한 참조하십시오 Humanoid:AddAccessory() 에서 인간형의 부모에 Accessory 를 연결하려면.
반환
코드 샘플
This code sample will wait for accessories to fully load, print out how many there are, and then destroy them all.
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() 메서드를 사용하여 다른 캐릭터에 모양을 할당할 수 있습니다.
또한 참조하세요
- Players:GetHumanoidDescriptionFromUserId() 는 전달된 사용자에 대한 아바타를 설명하는 HumanoidDescription 을 반환합니다.
- Players:GetHumanoidDescriptionFromOutfitId() 는 패라미터가 서버 측 의상 자산과 일치하도록 초기화된 HumanoidDescription 를 반환합니다.
- Player:LoadCharacterWithHumanoidDescription() 에서 생성되는 플레이어는 전달된 HumanoidDescription 의 모양을 가지고 있습니다.
반환
GetBodyPartR15
이 메서드는 무엇이 부품인지, 또는 부품이 R15 신체 부분이 아닌 경우를 반환합니다.이 메서드는 실제 신체 부분 이름과 무관하게 개발자가 플레이어 신체 부분을 검색할 수 있도록 하며, 열거형을 반환하는 대신 반환합니다.
Humanoid:ReplaceBodyPartR15()와 함께 사용할 수 있습니다.예를 들어, 플레이어의 신체 부분이 무언가에 닿으면 이 함수는 부품 인스턴스를 반환합니다.개발자는 머리나 팔과 같은 신체의 어느 부분이었는지 조사할 수 있습니다.그런 다음 그 부분이 무엇이었는지에 따라 개발자는 게임 플레이 작업을 수행하거나 다른 부분으로 교체하여 손상을 표시할 수 있습니다.
이 메서드는 타격 위치가 중요한 게임에 유용할 수 있습니다.예를 들어, 플레이어가 다리에 타격을 받았는지 여부를 결정하고 부상에 따라 속도를 늦출 수 있습니다.
매개 변수
R15 바디 부품인지 확인하기 위해 지정된 부품.
반환
지정된 부품의 R15 신체 부분 유형 또는 부품이 신체 부분이 아닌 경우 알려지지 않음.
GetLimb
이 메서드는 지정된 Enum.Limb와 연결된 열거형 Part를 반환합니다. R15와 R6 장비 모두에서 작동합니다. 예를 들어:
-- R15용print(humanoid:GetLimb(character.LeftUpperLeg)) -- Enum.Limb.LeftLegprint(humanoid:GetLimb(character.LeftLowerLeg)) -- Enum.Limb.LeftLegprint(humanoid:GetLimb(character.LeftFoot)) -- Enum.Limb.LeftLeg-- R6용print(humanoid:GetLimb(character:FindFirstChild("Left Leg"))) -- Enum.Limb.LeftLeg
부품의 부모가 휴머노이드의 부모로 설정되지 않으면 Humanoid:GetLimb() 에러가 발생합니다.
매개 변수
반환
코드 샘플
Put this in a LocalScript. The output will vary based on if the humanoid is R6 or R15.
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
GetState
이 메서드는 현재 Enum.HumanoidStateType 를 반환하여 현재 Humanoid 가 수행하고 있는 활동, 예를 들어 점프나 수영을 설명합니다.
특정 상태를 활성화하거나 비활성화하려면 Humanoid:SetStateEnabled() 를 참조하고, 현재의 휴머노이드 상태를 변경하려면 Humanoid:ChangeState()를 참조하십시오.
반환
코드 샘플
This code, when placed inside a LocalScript in StarterPlayer.StarterCharacterScripts, will allow the player's character to perform a 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
- 상태 Humanoid를 활성화하거나 비활성화하려면 Humanoid:SetStateEnabled()
매개 변수
지정된 Enum.HumanoidStateType .
반환
지정된 Enum.HumanoidStateType가 활성화되었는지 여부.
코드 샘플
The code below sets the value of the humanoid jumping state to false using Humanoid:SetStateEnabled() and then retrieves and prints the value of this state (false) using Humanoid:GetStateEnabled().
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 인 경우 방향은 세계 CFrame 의 CurrentCamera 에 대한 것입니다.Roblox에서 음의 Z 방향은 "앞으로"로 간주되므로 다음 코드는 인간형이 CurrentCamera 방향으로 걷도록 합니다.
humanoid:Move(Vector3.new(0, 0, -1), true)
이 메서드가 호출될 때, Humanoid는 메서드가 다시 호출될 때까지 이동합니다.그러나 이 메서드는 Roblox의 기본 캐릭터 제어 스크립트에 의해 다음 프레임에서 덮어쓰일 것입니다.이를 피하려면 이 함수를 모든 프레임에서 RunService:BindToRenderStep() (예제 참조)로 호출하거나 StarterPlayerScripts에서 컨트롤 스크립트를 재정의하면 됩니다.
이 메서드는 서버에서 호출할 수 있지만, 이는 서버가 휴머노이드의 어셈블리의 네트워크 소유권을 가질 때만 수행해야 합니다.
또한 참조하십시오 Humanoid:MoveTo() 점으로 걸어가는 Humanoid 및 이 함수를 실제로 호출하는 Player:Move().
매개 변수
걸어갈 방향.
true 설정하면 moveDirection 매개 변수가 CurrentCamera 상대적으로 취해야 합니다.
반환
코드 샘플
This code sample uses the Humanoid:Move() function to make the player's Character walk in the direction of the Camera. RunService:BindToRenderStep() is required here as the default control scripts will overwrite the player's movement every frame.
To run this sample, place it inside a LocalScript parented to StarterCharacterScripts.
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
이 메서드는 Humanoid 가 지정된 위치로 걸어가려고 설정하여 속성 Humanoid.WalkToPoint 및 Humanoid.WalkToPart 을 시도하게 합니다.
위치 및 부품 매개 변수는 다음 및 다음 이 설정되는 것과 일치합니다.
부분 매개변수가 지정되면 Humanoid으로 이동하려고 계속 시도합니다.그러나 부품이 이동하면 포인트 Humanoid 가 걸어가는 위치가 부품과 동일한 위치로 이동됩니다 부품과 관련하여 .부분 매개 변수가 지정되지 않으면 Humanoid 이 걷고 있는 위치가 변경되지 않습니다.
휴머노이드의 도달 목표 상태는 목표에 도달하지 못하면 8초 후에 만료됩니다.이렇게 하면 NPC가 Humanoid.MoveToFinished 발사를 기다리는 데 갇히지 않습니다.이런 일이 발생하지 않도록 하려면 MoveTo를 반복적으로 호출하여 시간 제한이 계속 재설정되도록 해야 합니다.
MoveTo() 다음 조건 중 하나가 적용되면 종료됩니다:
캐릭터가 목적지에 도착합니다. 다양한 휴머노이드 속도와 프레임레이트를 고려하기 위해 ~1스터드 임계값이 있습니다.
캐릭터가 붙어서 8초 타이머가 만료됩니다.
값은 Humanoid.WalkToPoint 또는 Humanoid.WalkToPart 가 변경됩니다.
스크립트가 새로운 Humanoid:Move() 매개 변수로 moveDirection 를 호출합니다.
매개 변수
Humanoid.WalkToPoint 설정할 위치.
설정할 BasePart 에 대한 Humanoid.WalkToPart.
반환
코드 샘플
This code sample includes a function that avoids the 8 second timeout on Humanoid:MoveTo() by calling Humanoid:MoveTo() again before the timeout elapses. It also includes an optional andThen parameter where developers can pass a function to be called when the humanoid reaches its destination.
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 에 속하는 모든 개체를 가져옵니다.
반환
코드 샘플
This code sample will wait for accessories to fully load, print out how many there are, and then destroy them all.
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 는 실패합니다.
문자에 부모가 될 Class.Part``Class.Instance 이 될 문자.
반환
SetStateEnabled
이 메서드는 지정된 Enum.HumanoidStateType 가 활성화되었는지 여부를 Humanoid 에 설정합니다.특정 Enum.HumanoidStateType 가 비활성화되면 Humanoid 는 결코 그 상태에 들어갈 수 없습니다.상태를 변경하려는 시도가 Humanoid:ChangeState() 또는 Roblox 내부 코드 Humanoid를 사용하여 수행되든 상관없이 이는 사실입니다.
서버에서 SetStateEnabled()를 사용하면 클라이언트에 변경 사항이 복제되지 않으며, 그 반대의 경우도 마찬가지입니다.
매개 변수
활성화하거나 비활성화할 Enum.HumanoidStateType 가 될 수 있습니다.
가 활성화되어야 하는 경우, 가 비활성화되어야 하는 경우, 가 비활성화되어야 합니다.
반환
코드 샘플
The following sample will require a one second cooldown after a Humanoid has landed before it is able to jump again.
To try this sample, place it inside a LocalScript in StarterCharacterScripts|StarterPlayer.StarterCharacterScripts.
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.Health 의 Humanoid 를 지정된 수량 으로 줄입니다. 그렇지 않으면 보호되지 않는 경우 ForceField
이 메서드는 금액 매개 변수에 대해 음수 값을 허용합니다.이렇게 하면 휴머노이드의 Humanoid.Health가 증가합니다.그러나 이는 아무런 ForceField 가 없을 경우에만 효과가 있습니다.
포스필드가 손상을 방지하는 방법은 무엇인가요
A 는 다음 조건 중 하나를 충족하면 보호되는 것으로 간주됩니다: A 는 다음 조건 중 하나를 충족하면 보호되는 것으로 간주됩니다:
현재 존재하는 모든 에 상관없이 피해를 입히려면 를 직접 설정하십시오.
For more information on how ForceFields 보호 Humanoids 방법에 대한 자세한 내용은 ForceField 페이지를 참조하십시오.
매개 변수
손상, 또는 Humanoid.Health.
반환
코드 샘플
This code, put in a LocalScript, would make the local player take 99 damage only if a ForceField wasn't present.
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 는 관련된 Backpack 의 부모가 될 것입니다.The unequipped will be parented to the of the Player related to the Humanoid .
Tool가 장착되지 않으면 이 메서드는 아무 것도 하지 않습니다.
NPC(Non Player Characters, 플레이어가 아닌 캐릭터)에 의해 가 장착될 수는 있지만, 이 메서드는 상응하는 와만 작동합니다.이는 장착되지 않은 것을 부모로 지정하기 위해 개체가 필요하기 때문입니다.
참조하세요:
- 대신 Tool를 장착하려면 Humanoid:EquipTool()를 사용하십시오
반환
코드 샘플
The following sample will bind the U key to unequip any Tool|Tools the Player currently has equipped.
To use this sample, place it inside a LocalScript within StarterPlayerScripts|StarterPlayer.StarterPlayerScripts.
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 로 캐시됩니다.
이 메서드는 문자의 모양을 변경하기 위해 이 메서드만 사용되고 호출 사이에 다른 수단을 통해 변경되지 않는다는 가정을 통해 최적화됩니다.호출 사이에 캐릭터에 변경이 적용되면 이 메서드는 패스된 HumanoidDescription 정확하게 캐릭터를 반영하지 않을 수 있습니다.이 메서드를 캐릭터를 업데이트하는 다른 수단과 함께 사용하려는 경우, Humanoid:ApplyDescriptionReset() 는 항상 캐릭터가 전달된 HumanoidDescription을 반영하도록 보장합니다.
또한 참조하세요
- Humanoid:GetAppliedDescription() 는 현재 인간형에 적용된 HumanoidDescription 을 반환합니다.
- Players:GetHumanoidDescriptionFromUserId() 는 전달된 사용자에 대한 아바타를 설명하는 HumanoidDescription 을 반환합니다.
- Players:GetHumanoidDescriptionFromOutfitId() 는 패라미터가 서버 측 의상 자산과 일치하도록 초기화된 HumanoidDescription 를 반환합니다.
- Player:LoadCharacterWithHumanoidDescription() 에서 생성되는 플레이어는 전달된 HumanoidDescription 의 모양을 가지고 있습니다.
매개 변수
문자를 일치시키려는 HumanoidDescription 인스턴스.
반환
ApplyDescriptionReset
이 양보 방법은 외부 변경 후에도 문자의 모양이 HumanoidDescription에 일치하도록 만듭니다.패스된 HumanoidDescription 의 복사본은 HumanoidDescription 에 대한 Humanoid 로 캐시됩니다.
이 메서드는 변경 사항이 사용하지 않는 HumanoidDescription 시스템(예: 사용하지 않는 HumanoidDescription 또는 ApplyDescriptionReset() 또는 ApplyDescription() )에도 불구하고 항상 문자가 반영되도록 합니다.이는 최적화된 와 대조적이며, 문자가 시스템을 통해 변경되지 않은 경우에는 잘못 적용될 수 있는 을 적용할 수 있습니다.
매개 변수
문자를 일치시키려는 HumanoidDescription 인스턴스.
반환
이벤트
Climbing
Humanoid가 오르는 속도가 변경될 때 발화합니다.
Humanoids 는 Parts 또는 TrussParts 으로 만들어진 사다리를 올라갈 수 있습니다.
Humanoids 클라이밍은 그들의 Humanoid.WalkSpeed의 70%에서 이루어집니다.
이 이벤트는 Humanoid 가 등반을 중지할 때 항상 속도 0으로 발생하지는 않습니다.
참조하세요:
- 수영과 실행을 위해 Humanoid.Swimming 및 Humanoid.Running 이벤트를 참조하십시오
- 또한 Humanoid 이벤트를 사용하여 등반 중인 Humanoid.StateChanged 를 감지할 수 있습니다
- Humanoid:SetStateEnabled() 함수를 사용하여 등반을 비활성화할 수 있습니다
매개 변수
코드 샘플
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가 0에 도달할 때, 즉 Humanoid.Health가 0에 도달할 때 발생합니다.이는 머리를 그들의 Humanoid.Torso에서 분리하거나 건강 속성을 직접 설정하여 발생할 수 있습니다.
이 이벤트는 Humanoid 가 Workspace 의 후손인 경우에만 발생합니다. 만약 Dead``Enum.HumanoidStateType 가 비활성화되면 발생하지 않습니다.
코드 샘플
The code below would print the player's name, followed by "has died!", whenever a player dies. For example, if the player was named "Shedletsky", "Shedletsky has died!" would be printed to the output when they 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 에 들어갑니다.이 일이 발생하면 이벤트가 활성 값 false로 발사되고, Humanoid.GettingUp는 활성 값 true로 발사됩니다.
매개 변수
FreeFalling
이 이벤트는 Humanoid 가 들어가거나 떠날 때 발생합니다 Freefall``Enum.HumanoidStateType .
활성 매개 변수는 가 상태 에 들어가거나 나가는지 여부를 나타냅니다.
비록 상태 가 일반적으로 지상에 도달하면 종료되지만, 상태가 변경되는 동안 상태 가 활성 과 같은 값을 false 으로 발사할 수 있습니다.만약 상태가 떨어지는 동안 상태가 변경되면.이러한 이유로, Humanoid.StateChanged 을 사용하고 착륙한 Landed 때 작동하는 Humanoid 상태를 수신해야 합니다.
매개 변수
GettingUp
이 이벤트는 Humanoid 가 상태 Enum.HumanoidStateType.GettingUp 에 들어가거나 떠날 때, 상태 Humanoid 가 곧 후에 활성화되는 전환 상태, 즉 FallingDown (3초) 또는 Ragdoll (1초) 상태에 들어가거나 떠날 때 발생합니다.
Humanoid 가 다시 일어서려고 할 때, 이 이벤트는 잠시 후에 active 매개 변수로 다시 발사하기 전에 true 매개 변수의 active 과 false 매개 변수로 다시 발사합니다.
Humanoid를 강제로 떨어뜨리려면 Humanoid:ChangeState() 함수를 사용하여 Enum.HumanoidStateType.FallingDown로 전환합니다.
매개 변수
HealthChanged
이 이벤트는 변경될 때 Humanoid.Health 발생합니다.그러나 체력이 Humanoid.MaxHealth 와 같은 값으로 증가하거나 더 높은 값으로 증가하면 발사되지 않습니다.
When Humanoid.Health 가 0에 도달하면 Humanoid 가 죽고 Humanoid.Died 이벤트가 발생합니다. 이 이벤트는 값 0으로 발생합니다.
매개 변수
새로운 값 Humanoid.Health의 새로운 값.
코드 샘플
The following example determines the change in health, printing it to the output. It will only work in a LocalScript.
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)
This code sample allows you to create a simple color-changing health bar using two nested Frames. Paste this into a LocalScript on the inner frame.
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 에 들어갑니다.
점프할 때, 이 이벤트는 잠시 후에 매개변수로 다시 발사하기 전에 매개변수의 매개변수로 다시 발사합니다.이 두 번째 발사는 착륙과 일치하지 않습니다; 그것을 위해, 착륙을 듣기 위해 을 사용하십시오.
Humanoid:SetStateEnabled() 함수를 사용하여 점프를 비활성화할 수 있습니다.
매개 변수
MoveToFinished
이 이벤트는 Humanoid가 목표를 선언한 Humanoid.WalkToPoint 및 Humanoid.WalkToPart 속성으로 걸어가는 것을 완료할 때 발생합니다.
Humanoid.WalkToPoint 및 Humanoid.WalkToPart 속성은 개별적으로 설정하거나 Humanoid:MoveTo() 함수를 사용하여 설정할 수 있습니다.
Humanoid가 8초 이내에 목표에 도달하면 이 이벤트는 도달했습니다로 반환됩니다.목표가 8초 내에 달성되지 않으면 Humanoid 가 걷기를 중지하고 도달 은 거짓이 됩니다.이 제한 시간은 제한 시간 기간 내에서 Humanoid:MoveTo() 다시 호출하여 재설정할 수 있습니다.
매개 변수
코드 샘플
This code sample includes a function that avoids the 8 second timeout on Humanoid:MoveTo() by calling Humanoid:MoveTo() again before the timeout elapses. It also includes an optional andThen parameter where developers can pass a function to be called when the humanoid reaches its destination.
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
이 이벤트는 Humanoid 가 들어가거나 떠날 때 발생합니다 PlatformStanding``Enum.HumanoidStateType .
Humanoid 상태가 PlatformStanding 있을 때, Humanoid.PlatformStand 속성이 true가 됩니다.
휘발성 은 true로 설정되었지만, 휘발성 은 이동할 수 없습니다. 자세한 내용은 휘발성 을 참조하십시오.
플랫폼 스탠드 Enum.HumanoidStateType 는 이제 비활성화된 Platform 부품과 연결되었습니다. 그럼에도 개발자들은 여전히 사용할 수 있습니다.
매개 변수
Ragdoll
이 이벤트는 Humanoid 가 들어가거나 떠날 때 발생합니다 Ragdoll``Enum.HumanoidStateType .
active 매개 변수에는 입력 또는 나가기를 나타내는 값 true 또는 false가 있습니다.
Humanoid:SetStateEnabled()를 사용하여 레그돌 상태에 머무르기 위해 가동 중지 상태를 비활성화합니다.
참조하세요:
- Humanoid.FallingDown for the Humanoid 이벤트, which behaves similarly to FallingDown 상태와 연결되어 Ragdoll와 유사한 동작을 수행합니다
매개 변수
Running
이 이벤트는 변경하는 Humanoid의 속도가 변경될 때 발생합니다.
평균적으로 커버를 실행하는 동안 Humanoids 스터드 당 초당 그들의 Humanoid.WalkSpeed 입니다.
Humanoid이 이벤트를 실행하는 것을 중지하면 속도 0으로 발사됩니다.
참조하세요:
- 수영과 등반을 위해 Humanoid.Swimming 및 Humanoid.Climbing 이벤트를 참조하십시오
- 또한 Humanoid 이벤트를 사용하여 실행 중인 Humanoid.StateChanged 를 감지할 수 있습니다
매개 변수
코드 샘플
Demonstrates connecting to the Humanoid.Running event. The event is connected to every player's humanoid that joins.
The function connected will print whether or not the humanoid is running based on the speed.
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 매개 변수가 false 이고 currentSeatPart 매개 변수가 nil이 됩니다.
참조하세요:
- Humanoid.Sit , 현재 인간형이 앉아 있는지 여부를 나타내는 것
- Humanoid.SeatPart , 인간형이 현재 앉아 있는 좌석을 나타내는 경우, 있는 경우.
매개 변수
코드 샘플
This code sample demonstrates when the local player's Character sits down or stands up. It should be placed inside a LocalScript within StarterCharacterScripts in order to run when the player's character spawns in.
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 가 정지해 있는지 알아야 합니다.
또한 참조하세요
- Humanoid:GetState() 및 Humanoid:ChangeState() 상태를 가져오고 설정하기 위해.
- Humanoid:SetStateEnabled() 특정 상태를 활성화하고 비활성화하기 위해.
매개 변수
인간의 이전 상태 입력.
인간의 현재 상태 입력.
코드 샘플
Emits particles from the local player's Player.Character when they jump. To try this code sample, place it inside a LocalScript parented to StarterCharacterScripts.
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)
The following sample will require a one second cooldown after a Humanoid has landed before it is able to jump again.
To try this sample, place it inside a LocalScript in StarterCharacterScripts|StarterPlayer.StarterCharacterScripts.
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에 호출되면 상태 변경 이벤트가 발생합니다.
매개 변수에는 이 상태가 현재 활성화되었는지를 나타내는 불린과 함께 질문에 포함된 Enum.HumanoidStateType가 포함됩니다.
참조하세요:
- 상태가 현재 활성화되었는지 찾으려면 Humanoid:GetStateEnabled()를 사용하십시오
- 상태 변경을 듣기 위해 Humanoid 사용 Humanoid.StateChanged
매개 변수
활성화된 상태가 변경된 대상 Enum.HumanoidStateType
상태가 활성화된 경우 true입니다.
코드 샘플
When a humanoid state changes for the Players.LocalPlayer, the code below prints whether the state has been enabled or disabled.
This code should work as expected when placed in a LocalScript.
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가 발생하지 않으며 개발자가 사용해서는 안됩니다
이 이벤트는 Humanoid 가 들어가거나 떠날 때 발생합니다 StrafingNoPhysics``Enum.HumanoidStateType .
Humanoid 가 상태 StrafingNoPhysics 에 들어갈 때 이 이벤트는 활성 매개 변수로 발생하며 true 의 활성 매개 변수입니다.이벤트는 상태 에서 떠날 때 활성 동일 거짓과 함께 다시 발생합니다.The event will fire again with active equal to false when the leaves the estado.
이 이벤트는 StrafingNoPhysics``Class.Humanoid 상태와 연결되어 있으며, **** 방향으로 이동할 때 Humanoid 가 발사되지 않습니다.이 상태는 현재 사용되지 않으며, Humanoid:ChangeState() 사용하여 설정하면 상태가 RunningNoPhysics로 되돌아갑니다.
매개 변수
Swimming
이 이벤트는 수영하는 속도가 Humanoid 물에서 변경될 때 발생합니다.This event fires when the speed at which a is swimming in Terrain water changes.
Humanoids 87.5%의 자신의 Humanoid.WalkSpeed에서 수영합니다.
이 이벤트는 수영을 멈출 때 항상 속도가 0으로 발생하는 것은 아닙니다 Humanoid.
참조하세요:
- 실행 및 등반에는 Humanoid.Running 및 Humanoid.Climbing 이벤트를 참조하십시오
- 또한 Humanoid 이벤트를 사용하여 수영 중인 Humanoid.StateChanged 를 감지할 수 있습니다
- Humanoid:SetStateEnabled() 함수를 사용하여 수영을 비활성화할 수 있습니다
매개 변수
Touched
이 이벤트는 인간형의 팔이 다른 BasePart와 접촉할 때 발생합니다.사지가 만지는 BasePart 및 사지 자체는 제공됩니다.
이 이벤트는 팔다리가 Humanoid에 접촉하면 발생하지 않습니다.
대안
Humanoid.Touched 이벤트는 유용하지만, 요구 사항에 더 적합한 대안이 있는지 고려해야 합니다.
- 대부분의 경우, 대신 관심의 이벤트를 연결하는 것이 좋습니다, 왜냐하면 이벤트는 휴머노이드가 이동할 때 지속적으로 발생하기 때문입니다.예를 들어, 피구 게임에서는 Touched 대신 공에 대한 Humanoid.Touched 이벤트를 연결하는 것이 더 실용적일 것입니다.
- Humanoid가 땅에 착륙했을 때 작업을 수행하려고 할 때, Humanoid.StateChanged 이벤트가 더 적합합니다.또는 대신 Humanoid.FloorMaterial에서 로봇이 비공기 물질 위에 서 있는지 확인할 수 있습니다.
노트
- 이 이벤트에 연결하면 모든 사지에 TouchTransmitter가 생성되어 이벤트가 발생합니다.
- 현재 BasePart.TouchEnded에 해당하는 것이 없습니다. Humanoids에 대한 것입니다.
매개 변수
접촉한 것은 Class.BasePart``Class.Humanoid 입니다.
코드 샘플
When placed inside a Player.Character model this code will give a player the 'Midas touch'. Everything their character touches will change to gold.
When the Humanoid dies, this change is undone and the golden BasePart|BaseParts are returned to their original state.
To test this out, place this code inside a Script and place it in StarterCharacterScripts|StarterPlayer.StarterCharacterScripts.
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)