Humanoid

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

หุ่นยนต์เป็นวัตถุพิเศษที่ให้โมเดลฟังก์ชันของตัวละครมันให้โมเดลมีความสามารถในการเดินทางกายภาพและโต้ตอบกับส่วนประกอบต่างๆของประสบการณ์ Roblox ได้มนุษย์เป็นตัวแทนเสมอภายใน Model และโมเดลคาดว่าจะเป็นการรวมของ BasePart และ Motor6D ส่วนรากของการรวมคาดว่าจะได้รับชื่อว่า HumanoidRootPartนอกจากนี้ยังคาดว่าส่วนที่มีชื่อว่า Head จะเชื่อมต่อกับส่วนลําตัวของตัวละครโดยตรงหรือโดยอ้อมโดยค่าเริ่มต้นมีสองประเภทอย่างเป็นทางการของตัวละครที่จัดหาโดย Roblox แต่ละอย่างมีกฎชุดของตนเอง:

R6

  • ชุดตัวละครพื้นฐานที่ใช้ 6 ส่วนสําหรับขา
  • ส่วน Head จะต้องถูกแนบไปกับส่วนที่มีชื่อว่า Torso หรือโฮมินอยด์จะตายทันที
  • การปรากฏตัวของส่วนตัวร่างกายใช้วัตถุ CharacterMesh
  • คุณสมบัติบางอย่าง เช่น Humanoid.LeftLeg และ Humanoid.RightLeg ทำงานได้เฉพาะกับ R6

R15

  • ซับซ้อนกว่า R6 แต่ยังยืดหยุ่นและแข็งแกร่งมากขึ้น
  • ใช้ 15 ส่วนสำหรับขา
  • ส่วน Head จะต้องถูกแนบไปกับส่วนที่มีชื่อว่า UpperTorso หรือมนุษย์หุ่นจะตายทันที
  • การปรากฏตัวของส่วนตัวร่างกายต้องถูกประกอบโดยตรง
  • สามารถปรับขนาดได้อย่างไดนามิกโดยใช้วัตถุพิเศษ NumberValue ภายใน Humanoid
  • หุ่นยนต์จะสร้างวัตถุ Vector3Value ที่มีชื่อ OriginalSize ภายในแต่ละข้อโดยอัตโนมัติ
  • หากมี NumberValue เป็นบิดาภายใน Humanoid กำลังติดตามจะใช้เพื่อควบคุมฟังก์ชันการขยาย:
    • ระดับความลึกของร่างกาย
    • ระดับความสูงของร่างกาย
    • ขนาดความกว้างของร่างกาย
    • ขนาดหัว

ตัวอย่างโค้ด

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.

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)

สรุป

คุณสมบัติ

  • อ่านพร้อมๆ กัน

    ตั้งค่าว่าตัวละครจะกระโดดโดยอัตโนมัติเมื่อพวกเขาชนกับอุปสรรคในฐานะผู้เล่นบนอุปกรณ์เคลื่อนที่

  • อ่านพร้อมๆ กัน

    การหมุนอัตโนมัติตั้งค่าว่ามนุษย์หุ่นยนต์จะหมุนไปในทิศทางที่พวกเขากําลังเคลื่อนที่หรือไม่

  • อ่านพร้อมๆ กัน

    เมื่อเปิดใช้งานแล้ว, การปรับขนาดอัตโนมัติที่เปิดใช้งานทำให้ขนาดของตัวละครเปลี่ยนแปลงตามค่าในความเปลี่ยนแปลงของค่าสเกลของมนุษย์โนอิด

  • อ่านพร้อมๆ กัน

    กำหนดว่าข้อต่อของมนุษย์จะแตกหรือไม่เมื่ออยู่ในสถานะ Enum.HumanoidStateType.Dead

  • อ่านพร้อมๆ กัน

    การเลื่อนที่ใช้กับตําแหน่งวัตถุของกล้องเมื่อกล้องวัตถุถูกตั้งค่าเป็น Humanoid นี้

  • อ่านพร้อมๆ กัน

    ควบคุมพฤติกรรมระยะทางของชื่อและการแสดงสุขภาพของมนุษย์หุ่นยนต์

  • อ่านพร้อมๆ กัน

    ตั้งข้อความของ Humanoid ที่แสดงบนหัวของพวกเขา

  • อ่านพร้อมๆ กัน
  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    อธิบาย Enum.Material ที่ Humanoid กําลังยืนอยู่ในขณะนี้หาก Humanoid ไม่ยืนบนอะไร ค่าของคุณสมบัตินี้จะเป็น อากาศ

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    อธิบายสุขภาพปัจจุบันของ Humanoid ในช่วง [0, Humanoid.MaxHealth ]

  • อ่านพร้อมๆ กัน

    ใช้ร่วมกับคุณสมบัติ DisplayDistanceType เพื่อควบคุมระยะทางที่แถบสุขภาพของมนุษย์สามารถมองเห็นได้

  • อ่านพร้อมๆ กัน

    การควบคุมเมื่อแถบสุขภาพของหุ่นยนต์สามารถแสดงได้

  • อ่านพร้อมๆ กัน

    กำหนดระยะทางออกจากพื้นที่ที่ Humanoid.RootPart ควรจะเป็น

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    หาก true , กระโดด Humanoid ด้วยแรงไปข้างบน

  • อ่านพร้อมๆ กัน

    ให้การควบคุมเกี่ยวกับความสูงที่ Humanoid กระโดดไป

  • อ่านพร้อมๆ กัน

    กำหนดจำนวนแรงแนวตั้งที่ใช้กับ Humanoid เมื่อกระโดด

  • อ่านพร้อมๆ กัน

    ค่าสูงสุดของมนุษย์หุ่น Health

  • อ่านพร้อมๆ กัน

    มุมลาดสูงสุดที่มนุษย์หุ่นยนต์สามารถเดินได้โดยไม่ลื่น

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    อธิบายทิศทางที่ Humanoid กําลังเดินอยู่

  • อ่านพร้อมๆ กัน

    ใช้ร่วมกับคุณสมบัติ Humanoid.DisplayDistanceType เพื่อควบคุมระยะทางที่ชื่อของฮิวแมนสามารถมองเห็นได้

  • อ่านพร้อมๆ กัน

    ควบคุมว่าชื่อและแถบสุขภาพของมนุษย์หุ่นยนต์สามารถมองเห็นได้หลังกำแพงหรือวัตถุอื่นได้หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดว่า Humanoid อยู่ในสถานะ Enum.HumanoidStateType.PlatformStanding ในปัจจุบันหรือไม่

  • อ่านพร้อมๆ กัน

    ช่วยให้นักพัฒนาสามารถปิดการทำงานที่ผู้เล่น Character|character ตายหากคอ Motor6D ถูกลบหรือถูกแยกออกแม้เพียงชั่วครู่

  • อ่านพร้อมๆ กัน

    อธิบายว่าสิ่งนี้ Humanoid ใช้ริกเกอร์ตัวละคร R6 รุ่นเก่าหรือริกเกอร์ตัวละคร R15 ใหม่

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    การอ้างอิงถึงวัตถุ HumanoidRootPart ของมนุษย์

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    การอ้างอิงถึงที่นั่งที่ Humanoid กําลังนั่งอยู่ในปัจจุบัน ถ้ามี

  • อ่านพร้อมๆ กัน

    อธิบายว่า Humanoid นั่งอยู่ในปัจจุบันหรือไม่

  • อ่านพร้อมๆ กัน

    อธิบายตำแหน่ง 3D ที่ Player ควบคุม Humanoid ล่าสุดในโลกขณะใช้ Tool

  • อ่านพร้อมๆ กัน

    กำหนดว่าคุณสมบัติ JumpHeight (ปลอม) หรือ Humanoid.JumpPower (จริง) จะถูกใช้

  • อ่านพร้อมๆ กัน

    อธิบายความเร็วในการเคลื่อนไหวสูงสุดของหุ่นยนต์ในสตัดต่อวินาที

  • อ่านพร้อมๆ กัน

    การอ้างอิงถึงส่วนที่ตำแหน่งของมันกำลังพยายามจะถึงโดยหุ่นยนต์

  • อ่านพร้อมๆ กัน

    ตำแหน่งที่หุ่นยนต์กําลังพยายามไปถึงหลังจากทําการโทรไปที่ Humanoid:MoveTo()

วิธีการ

อีเวนต์

คุณสมบัติ

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.

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

อ่านพร้อมๆ กัน

คุณสมบัติการหมุนอัตโนมัติอธิบายว่ามนุษย์หุ่นยนต์จะหมุนไปในทิศทางที่พวกเขาเคลื่อนที่หรือไม่เมื่อตั้งค่าเป็นจริงแล้ว รูปแบบตัวละครจะเปลี่ยนไปสู่ทิศทางการเคลื่อนที่ของมนุษย์เทียมในขณะที่เดินไปรอบๆเมื่อตั้งค่าเป็น false โมเดลตัวละครจะยังคงติดอยู่ในการหมุนปัจจุบันไม่ว่าจะมีแรงหมุนถูกใช้กับ HumanoidRootPart หรือไม่

หากรูปแบบตัวละครเป็นตัวละครของผู้เล่นแล้วพฤติกรรมการหมุนของ Humanoid จะได้รับอิทธิพลจากคุณสมบัติ RotateType ของ UserGameSetting

เมื่อคุณสร้างคุณสมบัติ AutoRotate เป็นจริง คุณสมบัติ RotateType จะมีผลกระทบต่อการหมุนของ Humanoid ดังต่อไปนี้:


<th>พฤติกรรม</th>
<th>บริบท</th>
</tr>
</thead>
<tbody>
<tr>
<td>การเคลื่อนไหวที่เกี่ยวข้อง</td>
<td />
<td />
</tr>
<tr>
<td>กล้องสัมพันธ์</td>
<td>ตัวละครจะหมุนเพื่อหันหน้าไปในทิศทางของกล้อง</td>
<td>ผู้เล่นมีกล้องซูมเข้าสู่มุมมองบุคคลที่หนึ่งหรือพวกเขาอยู่ในโหมดล็อคเปลี่ยนเกียร์</td>
</tr>
</tbody>
ประเภทการหมุน

ตัวอย่างโค้ด

This script adds the functionality of a button to a part, which switches the AutoRotate property of whoever touches it.

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

อ่านพร้อมๆ กัน

หุ่นยนต์มีหกค่าระดับเด็กรวมถึง BodyDepthScale , BodyHeightScale , BodyProportionScale , BodyTypeScale , BodyWidthScale , HeadScale .การเปลี่ยนค่าของสาเหตุใด ๆ เหล่านี้ทำให้ส่วนของร่างกายและอุปกรณ์เสริมของตัวละครเปลี่ยนขนาด แต่เฉพาะถ้า AutomaticScalingEnabled เป็นจริง

BreakJointsOnDeath

อ่านพร้อมๆ กัน

กำหนดว่าข้อต่อของมนุษย์จะแตกหรือไม่เมื่ออยู่ในสถานะ Enum.HumanoidStateType.Dead ค่าเริ่มต้นคือจริง

CameraOffset

อ่านพร้อมๆ กัน

คุณสมบัติ CameraOffset กำหนดการเคลื่อนที่ไปยังตําแหน่งวัตถุของกล้องเมื่อ Camera.CameraSubject ถูกตั้งค่าเป็น Humanoid นี้

ค่าส่วนลบถูกใช้ในพื้นที่วัตถุเมื่อเทียบกับตำแหน่งของ HumanoidRootPart ของมนุษย์ตัวอย่างเช่น การเคลื่อนที่ออฟเซ็ต Vector3 ค่าของ (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.

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)
อ่านพร้อมๆ กัน

คุณสมบัติ ระยะทางการแสดงผล ควบคุมพฤติกรรมระยะทางของชื่อและการแสดงสุขภาพของหุ่นยนต์คุณสมบัตินี้ถูกตั้งค่าโดยใช้ enum Enum.HumanoidDisplayDistanceType ที่มีสามค่าที่ใช้ได้แต่ละค่ามีกฎชุดของตนเอง:

  • เมื่อตั้งค่าเป็น Viewer หุ่นยนต์จะเห็นชื่อ/สุขภาพของหุ่นยนต์อื่นๆ ภายในระยะของตัวเอง 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.

Displaying a Humanoid's Health and Name

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

DisplayName

อ่านพร้อมๆ กัน

DisplayName เป็นคุณสมบัติที่กำหนดการแสดงชื่อของ Humanoid เมื่อมองเห็นได้โดยค่าเริ่มต้น หุ่นยนต์ใหม่จะมีค่าของสตริงว่างเปล่าหาก DisplayName เป็นสตริงว่างเปล่า การแสดงชื่อของมนุษย์หุ่นจะเริ่มต้นด้วยชื่อของพ่อแม่ของมนุษย์หุ่น

การโหลดตัวละครผู้เล่น

เมื่อผู้เล่นโหลดตัวละครของพวกเขาไม่ว่าจะโดยอัตโนมัติหรือผ่านการใช้ LoadCharacter() คนหุ่นยนต์ที่สร้างโดยเครื่องยนต์จะมีคุณสมบัติ DisplayName ของผู้เล่นตั้งค่าเป็นคุณสมบัติ DisplayName ของผู้เล่น

ตัวละครเริ่มต้นและ StarterHumanoid

เมื่อ Humanoid ที่มีชื่อ StarterHumanoid ได้รับการสืบทอดจาก StarterPlayer หรือเมื่อมนุษย์นอยด์ปรากฏในโมเดลที่ชื่อว่า StarterCharacter คุณสมบัติ DisplayName จะได้รับการเคารพเมื่อตัวละครโหลดโดยผู้เล่นในเกมเครื่องยนต์จะเขียนทับคุณสมบัติ DisplayName ของ Humanoid ด้วยคุณสมบัติ DisplayName ของผู้เล่นหากคุณสมบัติ Humanoid.DisplayName ของ StarterHumanoid เป็นสตริงว่างเปล่า

EvaluateStateMachine

อ่านพร้อมๆ กัน

FloorMaterial

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

นี่เป็นคุณสมบัติอ่านได้ที่อธิบายถึง Enum.Material ที่ Humanoid กําลังยืนอยู่ในขณะนี้มันทำงานร่วมกับทั้ง voxels ปกติ 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 เพื่อควบคุมระยะทางที่แถบสุขภาพของมนุษย์สามารถมองเห็นได้

ดู ชื่อตัวละคร/การแสดงสุขภาพ สำหรับคู่มืออย่างละเอียดเกี่ยวกับการควบคุมรูปลักษณ์ของชื่อตัวละครและแถบสุขภาพ

อ่านพร้อมๆ กัน

คุณสมบัตินี้ควบคุมเมื่อแถบสุขภาพของมนุษย์หุ่นยนต์สามารถแสดงได้โดยค่าเริ่มต้นคุณสมบัตินี้จะถูกตั้งค่าเป็น DisplayWhenDamaged ซึ่งทำให้แถบสุขภาพแสดงเฉพาะเมื่อ humanoid ของคุณ Health น้อยกว่าของมัน MaxHealthนอกจากนี้ยังสามารถตั้งค่าเป็น AlwaysOn ซึ่งทำให้แถบสุขภาพแสดงเสมอ หรือ AlwaysOff ซึ่งป้องกันไม่ให้แสดงเลย

โปรดทราบว่าคุณสมบัตินี้ทำงานอย่างอิสระจากคุณสมบัติของหุ่นยนต์ที่เป็นความรับผิดชอบในการทำให้แถบสุขภาพหายไปในระยะทางที่กำหนด HealthDisplayDistanceหาก Humanoid.HealthDisplayType|HealthDisplayType ถูกตั้งค่าเป็น AlwaysOn จะยังคงจางไปขึ้นอยู่กับวิธีที่ HealthDisplayDistance กำหนดค่า

ดู ชื่อตัวละคร/การแสดงสุขภาพ สำหรับคู่มืออย่างละเอียดเกี่ยวกับการควบคุมรูปลักษณ์ของชื่อตัวละครและแถบสุขภาพ

HipHeight

อ่านพร้อมๆ กัน

กำหนดระยะ (ในสตัด) ออกจากพื้นที่ RootPart ควรจะเป็นเมื่อมนุษย์หุ่นยนต์ยืนสิ่งที่ RigType มีอิทธิพลต่อวิธีที่คุณสมบัตินี้ทำงาน

สำหรับแท่น R15 ความสูงสะโพกที่เหมาะสมจะถูกตั้งไว้เพื่อให้แน่ใจว่าความสูงของ RootPart ถูกต้องความสูงของขาไม่ได้ใช้ความสูงโดยรวมของหุ่นยนต์สามารถอธิบายได้ด้วยสูตรต่อไปนี้:


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

สำหรับ R6 ริก, HipHeight แทนที่จะอธิบายความเคลื่อนที่แบบสัมพันธ์ ความสูงโดยรวมของมนุษย์หุ่นยนต์สามารถอธิบายได้ในสูตรต่อไปนี้:


Height = LeftLeg.Size.Y + (0.5 * RootPart.Size.Y) + HipHeight
ไม่ซ้ำ
อ่านพร้อมๆ กัน

หาก true , กระโดด Humanoid ด้วยแรงไปข้างบนเท่ากับมูลค่าของ Humanoid.JumpPower หรือความสูงของ Humanoid.JumpHeight , ขึ้นอยู่กับมูลค่าของ Humanoid.UseJumpPower .

JumpHeight

อ่านพร้อมๆ กัน

ให้การควบคุมเกี่ยวกับความสูงของการกระโดด Humanoid ในสตัดมูลค่าเริ่มต้นของคุณสมบัตินี้จะถูกกำหนดโดยมูลค่าของ StarterPlayer.CharacterJumpHeight ซึ่งเริ่มต้นที่ 7.2

แม้ว่าการตั้งค่าคุณสมบัตินี้เป็น 0 จะป้องกันไม่ให้มนุษย์หุ่นยนต์กระโดดได้อย่างมีประสิทธิภาพ แต่ขอแนะนำให้ปิดการกระโดดโดยการปิดใช้งานสถานะ Enum.HumanoidStateType.Jumping ผ่าน Humanoid:SetStateEnabled()

คุณสมบัตินี้จะปรากฏเฉพาะในหน้าต่าง คุณสมบัติ ถ้า Humanoid.UseJumpPower ถูกตั้งค่าเป็น ปิด เนื่องจากจะไม่เกี่ยวข้องอย่างอื่น (แทนที่จะใช้ Humanoid.JumpPower )

JumpPower

อ่านพร้อมๆ กัน

กำหนดจำนวนแรงแนวตั้งที่ใช้กับ Humanoid เมื่อกระโดดมูลค่าเริ่มต้นของคุณสมบัตินี้จะถูกกำหนดโดยมูลค่าของ StarterPlayer.CharacterJumpPower ซึ่งเริ่มต้นที่ 50 และถูกจำกัดระหว่าง 0 และ 1000โปรดทราบว่ากระโดดยังได้รับอิทธิพลจากคุณสมบัติ Workspace.Gravity ซึ่งกำหนดอัตราเร่งเนื่องจากแรงโน้มถ่วง

แม้ว่าการตั้งค่าคุณสมบัตินี้เป็น 0 จะป้องกันไม่ให้มนุษย์หุ่นยนต์กระโดดได้อย่างมีประสิทธิภาพ แต่ขอแนะนำให้ปิดการกระโดดโดยการปิดใช้งานสถานะ Enum.HumanoidStateType.Jumping ผ่าน Humanoid:SetStateEnabled()

คุณสมบัตินี้จะปรากฏเฉพาะในหน้าต่าง คุณสมบัติ ถ้า Humanoid.UseJumpPower ถูกตั้งค่าเป็น จริง เนื่องจากจะไม่เกี่ยวข้องอย่างอื่น (แทนที่จะใช้ Humanoid.JumpHeight )

MaxHealth

อ่านพร้อมๆ กัน

ค่าสูงสุดของมนุษย์หุ่น Health

มูลค่าของคุณสมบัตินี้ใช้คู่กับคุณสมบัติ Health เพื่อปรับขนาดการแสดงแถบสุขภาพเริ่มต้นเมื่อแฮนด์โลดของมนุษย์ Health ถึง MaxHealth แถบสุขภาพอาจไม่แสดงผลขึ้นอยู่กับคุณสมบัติ HealthDisplayType ของมัน

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.

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

ตัวอย่างโค้ด

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.

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

อ่านพร้อมๆ กัน

คุณสมบัติ 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.

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

อ่านพร้อมๆ กัน

กำหนดว่า Humanoid อยู่ในสถานะ Enum.HumanoidStateType.PlatformStanding ในปัจจุบันหรือไม่เมื่อถูกต้อง Humanoid อยู่ในสถานะที่ตกอย่างอิสระและไม่สามารถเคลื่อนที่ได้สถานะนี้มีพฤติกรรมคล้ายกับการนั่ง ยกเว้นการกระโดดจะไม่ปลดปล่อยมนุษย์หุ่นจากสถานะ

RequiresNeck

อ่านพร้อมๆ กัน

ช่วยให้นักพัฒนาสามารถปิดการทำงานที่ผู้เล่น Character|character ตายหากคอ Motor6D ถูกลบหรือถูกแยกออกแม้เพียงชั่วครู่คุณสมบัตินี้จะเริ่มต้นเป็นจริง

อ่านพร้อมๆ กัน

ประเภทของฮาร์ดแวร์ อธิบายว่า Humanoid กำลังใช้ฮาร์ดแวร์ตัวละคร R6 รุ่นเก่าหรือฮาร์ดแวร์ตัวละคร R15 ใหม่

เครื่อง R6 ใช้ 6 เห็นได้ Parts ในขณะที่เครื่อง R15 ใช้ 15 เห็นได้ Partsแท่ง R15 มีข้อต่อมากกว่าแท่ง R6 ทำให้พวกเขามีความหลากหลายมากขึ้นเมื่อถูกแอนิเมชั่น

โปรดทราบว่าหากคุณสมบัตินี้ถูกตั้งค่าไม่ถูกต้อง Humanoid จะไม่ทํางานอย่างถูกต้องตัวอย่างเช่น หาก R15 humanoid ของ RigType ถูกตั้งค่าเป็น R6 แล้ว จะตายเนื่องจากไม่มี ที่เรียกว่า ทอร์โซ เชื่อมต่อกับ หัว ที่เรียกว่า ไม่มีใครเรียก

RootPart

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

การอ้างอิงถึงวัตถุ HumanoidRootPart ของมนุษย์หุ่นยนต์ส่วนรากที่ขับเคลื่อนส่วนรากของ Humanoid ที่ควบคุมการเคลื่อนไหวของมนุษย์หุ่นยนต์ผ่านโลก 3Dส่วนนี้มักจะมองไม่เห็น

สำหรับตัวละคร R15, Model.PrimaryPart ของรูปแบบ Player.Character ถูกตั้งค่าเป็น HumanoidRootPart สำหรับตัวอักษร R6 Model.PrimaryPart จะถูกตั้งค่าเป็นส่วน Head

SeatPart

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

ส่วนที่นั่งเป็นการอ้างอิงถึงที่นั่งที่ Humanoid กําลังนั่งอยู่ในปัจจุบันถ้ามีค่าของคุณสมบัตินี้อาจเป็น Seat หรือ VehicleSeatมันจะเป็น ไม่มี ถ้ามนุษย์ไม่ได้นั่งอยู่ในที่นั่งในขณะนี้

หมายเหตุ:

  • สำหรับ bool ที่อธิบายว่า Humanoid กําลังนั่งอยู่หรือไม่ในปัจจุบัน ดู Humanoid.Sit
อ่านพร้อมๆ กัน

คุณสมบัติ Sit เป็นบูลีนที่ระบุว่า Humanoid กําลังนั่งอยู่ในปัจจุบันหรือไม่Humanoids สามารถบังคับให้อยู่ในสถานะนั่งโดยการตั้งค่าค่าของคุณสมบัตินี้เป็นจริงหาก Humanoid ไม่ได้ติดกับที่นั่งในขณะที่อยู่ในสภาวะนั่ง มันจะล้มลงโดยไม่มีการชนกันในขาของมันA Humanoid สามารถหลบหนีจากสถานะการนั่งโดยการกระโดด

หมายเหตุ:

  • The Seat หรือ VehicleSeat ของ Humanoid กำลังนั่งอยู่บนสามารถรับได้โดยใช้คุณสมบัติ Humanoid.SeatPart
  • เป็นไปได้ที่จะตรวจพบเมื่อมนุษย์หุ่นยนต์นั่งโดยเชื่อมต่อกับเหตุการณ์ Humanoid.Seated

TargetPoint

อ่านพร้อมๆ กัน

อย่าใช้ คุณสมบัตินี้ทำงานได้เฉพาะในโหมดการทดลองที่เปิดใช้งานแล้วซึ่งถูกยกเลิกโดยสิ้นเชิง

คุณสมบัตินี้อธิบายตำแหน่ง 3D ในอวกาศที่ Player ควบคุมสิ่งนี้ 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 กำลังพยายามไปถึงคุณสมบัตินี้จะตั้งค่าโดยปกติเมื่อส่งส่วนเป็นอาร์กิวเมนต์ที่สองของฟังก์ชัน Humanoid:MoveTo() ของ Humanoid

เมื่อ WalkToPart ถูกตั้งค่าและมนุษย์กําลังพยายามอย่างใกล้ชิดที่จะไปถึงส่วน มันจะยังคงอัปเดตเป้าหมาย Vector3 เพื่อเป็นตําแหน่งของส่วน บวกกับ 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 แล้วหุ่นยนต์จะพยายามไปถึงตำแหน่ง 3D ที่ระบุโดย WalkToPoint โดยตรง

ข้อควรระวัง

  • ค่าของ 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.

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 ในอุปกรณ์เสริม Handle ของอุปกรณ์เสริม Part Errors: No errors found.หากพบหนึ่งรายการ ส่วน จัดการ จะเชื่อมต่อกับผู้ปกครองของ Attachment โดยใช้ Weld และการเชื่อมต่อจะถูกกำหนดค่าเพื่อให้ส่วน Attachments ใช้พื้นที่เดียวกัน

หากไม่พบ Attachment ที่จำเป็น แล้ว Accessory จะยังคงเป็นพ่อแม่ของมนุษย์หุ่นยนต์ แต่จะถูกแยกออก

โดยปกติแล้วการเชื่อมต่ออุปกรณ์จะถูกสร้างบนเซิร์ฟเวอร์ แต่สามารถสร้างบนไคลเอนต์ภายใต้เงื่อนไขบางอย่างได้ในสถานการณ์เหล่านี้ การโทรจากฝั่งคลายไปยัง AddAccessory() อาจไม่เสมอไปผลิตพฤติกรรมที่ต้องการและคุณสามารถใช้ BuildRigFromAttachments() การสร้างสรรค์

พารามิเตอร์

accessory: Instance

The Accessory ที่จะถูกแนบไป

ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

ตัวอย่างโค้ด

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.

[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

เริ่มจาก humanoid's 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.

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)

A script that generates an R15 character from scratch using a package's assetId.

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 บางรัฐจะเปลี่ยนโดยอัตโนมัติเมื่อตั้งค่า ตัวอย่างเช่น:

โปรดทราบว่าเพื่อตั้งสถานะ Humanoid โดยใช้วิธีนี้คุณต้องทำเช่นนั้นจาก LocalScript และลูกค้าต้องมี เจ้าของเครือข่าย ของ Player.Characterหรือคุณสามารถเรียกวิธีนี้จากด้านเซิร์ฟเวอร์ Script แต่เซิร์ฟเวอร์ต้องมีการเป็นเจ้าของเครือข่ายของตัวละครผู้เล่น

ดูเพิ่มเติม Humanoid:SetStateEnabled() เพื่อเปิดใช้งานหรือปิดใช้งานสถานะเฉพาะ, และ Humanoid:GetState() เพื่อรับสถานะ humanoid ปัจจุบัน

พารามิเตอร์

The Enum.HumanoidStateType ที่ Humanoid จะดำเนินการ

ค่าเริ่มต้น: "None"

ส่งค่ากลับ

()

ตัวอย่างโค้ด

This code, when placed inside a LocalScript in StarterPlayer.StarterCharacterScripts, will allow the player's character to perform a double jump.

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 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.RequiresHandle เป็น จริง จะไม่ทำงานหากพวกเขาไม่มีจัดการ, ไม่ว่าวิธีนี้จะใช้เพื่อติดตั้งพวกเขาหรือไม่

ดูเพิ่ม:

พารามิเตอร์

tool: Instance

The Tool ที่จะติดตั้ง

ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

GetAccessories

วิธีนี้จะคืนเป็นคอลเลกชันของวัตถุ Accessory ที่มนุษย์หุ่นยนต์กําลังสวมใส่อยู่ในปัจจุบันวัตถุทั้งหมดเช่น Accessory จะถูกรวมเข้าไป ไม่ว่าพวกเขาจะถูกแนบหรือไม่

หาก Humanoid ไม่มีวัตถุ Accessory ความว่างเปล่าจะถูกส่งคืน

ดูเพิ่มเติม Humanoid:AddAccessory() เพื่อติดตั้ง Accessory กับพ่อของมนุษย์หุ่นยนต์


ส่งค่ากลับ

ชุดของวัตถุ Accessory ที่เป็นพ่อของมนุษย์หุ่นยนต์

ตัวอย่างโค้ด

This code sample will wait for accessories to fully load, print out how many there are, and then destroy them all.

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

วิธีนี้จะคืนสำเนาของ humanoid's cached HumanoidDescription ซึ่งอธิบายลักษณะปัจจุบันของมันสิ่งนี้สามารถใช้เพื่อระบุลักษณะของตัวละครได้อย่างรวดเร็วและกำหนดลักษณะให้กับตัวละครอื่นโดยใช้วิธี Humanoid:ApplyDescription()

ดูเพิ่มเติม


ส่งค่ากลับ

GetBodyPartR15

วิธีนี้จะคืนสิ่งที่ Enum.BodyPartR15 เป็น Part หรือ Enum.BodyPartR15.Unknown ถ้าส่วนไม่ใช่ส่วนของร่างกาย R15วิธีนี้ช่วยให้นักพัฒนาสามารถดึงส่วนของร่างกายผู้เล่นอิสระจากชื่อส่วนของร่างกายจริงได้ แทนที่จะส่งคืน enum

สามารถใช้ร่วมกับ Humanoid:ReplaceBodyPartR15() ได้ตัวอย่างเช่น หากส่วนของร่างกายของผู้เล่นสัมผัสบางอย่าง ฟังก์ชันนี้จะคืนได้รับตัวอย่างส่วนนักพัฒนาสามารถมองหาส่วนใดของร่างกายที่เป็น เช่น หัวหรือแขนจากนั้นขึ้นอยู่กับส่วนที่เป็นอะไร ผู้พัฒนาสามารถดำเนินการบางอย่างในเกมหรือแทนที่ส่วนนั้นด้วยส่วนอื่น ๆ - อาจแสดงความเสียหาย

วิธีนี้สามารถมีประโยชน์สำหรับเกมที่ตำแหน่งการโจมตีมีความสำคัญตัวอย่างเช่น สามารถใช้เพื่อตรวจสอบว่าผู้เล่นถูกโจมตีที่ขาแล้วช้าลงตามอาการบาดเจ็บ

พารามิเตอร์

part: Instance

ส่วนที่ระบุถูกตรวจสอบเพื่อดูว่าเป็นส่วนของร่างกาย R15 หรือไม่

ค่าเริ่มต้น: ""

ส่งค่ากลับ

ประเภทร่างกาย R15 ของส่วนที่ระบุหรือไม่ทราบหากส่วนไม่ใช่ส่วนของร่างกาย

GetLimb

วิธีนี้ส่งคืน enum Enum.Limb ที่เกี่ยวข้องกับ Part ที่กำหนด มันทำงานได้ทั้งสำหรับ 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

The Part สำหรับซึ่ง Enum.Limb จะต้องดึงมา

ค่าเริ่มต้น: ""

ส่งค่ากลับ

ส่วน Enum.Limb ที่ตรงกับ

ตัวอย่างโค้ด

Put this in a LocalScript. The output will vary based on if the humanoid is R6 or R15.

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() เพื่อเปลี่ยนสถานะ humanoid ปัจจุบัน


ส่งค่ากลับ

ปัจจุบัน Enum.HumanoidStateType ของ Humanoid .

ตัวอย่างโค้ด

This code, when placed inside a LocalScript in StarterPlayer.StarterCharacterScripts, will allow the player's character to perform a double jump.

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().

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

()

วิธีนี้ทำให้ Humanoid เดินไปในทิศทางที่กำหนด Vector3

ข้อกำหนดแต่ถ้าพารามิเตอร์ relativeToCamera เป็น true ทิศทางจะเป็นค่าสัมพันธ์กับ CFrame ของ CurrentCameraเนื่องจากทิศทางเชิงลบ Z ถูกมองว่าเป็น "ไปข้างหน้า" ใน Roblox โค้ดต่อไปนี้จะทำให้มนุษย์เดินไปในทิศทางของ CurrentCamera


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

เมื่อวิธีนี้ถูกเรียก Humanoid จะย้ายจนกว่าวิธีจะถูกเรียกอีกครั้งอย่างไรก็ตาม วิธีนี้จะถูกเขียนทับในเฟรมถัดไปโดยสคริปต์การควบคุมตัวละครเริ่มต้นของ Robloxสิ่งนี้สามารถหลีกเลี่ยงได้โดยการเรียกฟังก์ชันนี้ทุกเฟรมโดยใช้ RunService:BindToRenderStep() (ดูตัวอย่าง) หรือเขียนทับสคริปต์การควบคุมใน StarterPlayerScripts

วิธีนี้สามารถเรียกใช้บนเซิร์ฟเวอร์ได้ แต่ควรทำเฉพาะเมื่อเซิร์ฟเวอร์มีสิทธิ์เป็นเจ้าของเครือข่าย เครื่องประกอบของมนุษย์ เท่านั้น

ดูเพิ่มเติม ซึ่งทำให้เดินไปยังจุดได้ และ ซึ่งเรียกฟังก์ชันนี้ได้อย่างมีประสิทธิภาพ

พารามิเตอร์

moveDirection: Vector3

ทิศทางที่จะเดินใน

ค่าเริ่มต้น: ""
relativeToCamera: boolean

ตั้งค่าเป็น true หากพารามิเตอร์ moveDirection ควรถูกนำมาเป็นค่าสัมพันธ์กับ CurrentCamera

ค่าเริ่มต้น: false

ส่งค่ากลับ

()

ตัวอย่างโค้ด

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.

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

()

วิธีนี้ทำให้ Humanoid เดินไปยังตำแหน่งที่กำหนดโดยการตั้งค่าคุณสมบัติ Humanoid.WalkToPoint และ Humanoid.WalkToPart

พารามิเตอร์สถานที่ และส่วน ตรงกับสิ่งที่ และ จะถูกตั้งค่า

หากพารามิเตอร์ส่วน ** ถูกระบุ ตัวเลือก Humanoid จะยังคงพยายามเดินไปยังจุดอย่างไรก็ตาม หากส่วนย้ายแล้วจุด Humanoid กำลังเดินไปจะย้ายไปอยู่ในตำแหน่งเดียวกัน ** เมื่อเทียบกับส่วน **หากพารามิเตอร์ส่วน ** ไม่ได้ระบุ ตำแหน่งที่ Humanoid กำลังเดินไปจะไม่เปลี่ยนแปลง

สถานะเป้าหมาย ของหุ่นยนต์ จะหมดอายุหลังจาก 8 วินาทีหากไม่สามารถบรรลุเป้าหมายได้สิ่งนี้ทำเพื่อให้ NPC ไม่ติดอยู่ในการรอ Humanoid.MoveToFinished ที่จะยิงหากคุณไม่ต้องการให้เกิดเหตุการณ์นี้ขึ้น คุณควรโทรซ้ำไปที่ MoveTo เพื่อให้เวลาหมดอายุยังคงรีเซ็ตต่อไป

MoveTo() สิ้นสุดลงถ้าเงื่อนไขใดๆ ต่อไปนี้มีผลบังคับใช้:

  • ตัวละครมาถึงจุดหมาย

  • ตัวละครติดอยู่และนับถอยหลังแปดวินาทีหมดลง

  • ค่าของทั้ง Humanoid.WalkToPoint หรือ Humanoid.WalkToPart เปลี่ยนแปลง

  • สคริปต์เรียก Humanoid:Move() ด้วยพารามิเตอร์ใหม่ moveDirection

  • สคริปต์เปลี่ยนคุณสมบัติ CFrame ของ RootPart .

พารามิเตอร์

location: Vector3

ตำแหน่งที่จะตั้ง Humanoid.WalkToPoint ไป

ค่าเริ่มต้น: ""
part: Instance

The BasePart เพื่อตั้ง Humanoid.WalkToPart ไปยัง

ค่าเริ่มต้น: "nil"

ส่งค่ากลับ

()

ตัวอย่างโค้ด

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.

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 จะลบหมวกและอุปกรณ์อื่นๆ ทั้งหมด

วิธีนี้ลบวัตถุ Accessory โดยเรียก Instance:Destroy() บนพวกเขาซึ่งหมายความว่า Parent ของอุปกรณ์จะถูกตั้งค่าเป็น nil และถูกล็อค

ดูเพิ่มเติม 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.

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

The Class.Part``Class.Instance ซึ่งจะถูกผูกกับตัวละคร

ค่าเริ่มต้น: ""

ส่งค่ากลับ

SetStateEnabled

()

วิธีนี้กำหนดว่าให้ใช้งานสิ่งที่เรียกว่า Enum.HumanoidStateType สําหรับ Humanoid หรือไม่เมื่อปิดใช้งานเฉพาะ Enum.HumanoidStateType จะไม่สามารถเข้าสู่สถานะนั้นได้อีกต่อไป Humanoidสิ่งนี้เป็นจริงไม่ว่าจะพยายามเปลี่ยนสถานะโดยใช้ Humanoid:ChangeState() หรือรหัสภายใน Roblox Humanoid ก็ตาม

โปรดทราบว่าการใช้ SetStateEnabled() บนเซิร์ฟเวอร์ไม่สามารถสร้างการเปลี่ยนแปลงให้กับไคลเอนต์ได้ หรือในทางกลับกัน

พารามิเตอร์

The Enum.HumanoidStateType ที่จะเปิดใช้งานหรือปิดใช้งาน

ค่าเริ่มต้น: ""
enabled: boolean

หากต้องการเปิดใช้งาน หาก ถูกปิดใช้งาน

ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

ตัวอย่างโค้ด

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.

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.Health ของ Humanoid โดยจํานวน ** ที่กำหนดหากไม่ได้รับการคุ้มครองโดย ForceField

วิธีนี้รับค่าลบสำหรับพารามิเตอร์ จำนวน ได้จะเพิ่ม Humanoid.Health ของมนุษย์หุ่นยนต์อย่างไรก็ตามนี้จะมีผลเฉพาะถ้าไม่มี ForceField ปรากฏ

ForceFields ป้องกันการโจมตีด้วยการรับความเสียหายอย่างไร

A Humanoid ถือว่าได้รับการคุ้มครองโดย ForceField หาก A ForceField ตรงกับหนึ่งในเกณฑ์ต่อไปนี้:

เพื่อสร้างความเสียหายให้กับ Humanoid ไม่ว่าจะมี ForceFields ปัจจุบันหรือไม่ ให้ตั้ง Humanoid.Health โดยตรง

สำหรับข้อมูลเพิ่มเติมเกี่ยวกับวิธีการ ForceFields ปกป้อง Humanoids ดูที่หน้า ForceField

พารามิเตอร์

amount: number

ความเสียหายหรือจำนวนที่จะถูกหักออกจาก Humanoid.Health

ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

ตัวอย่างโค้ด

This code, put in a LocalScript, would make the local player take 99 damage only if a ForceField wasn't present.

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

ไม่ได้ติดตั้ง จะถูกสืบทอดไปยัง ของ ที่เกี่ยวข้องกับ 1>

หากไม่มี Tool ถูกติดตั้งวิธีนี้จะไม่ทำอะไรเลย

แม้ว่า Tools จะสามารถติดตั้งโดย NPCs (ตัวละครที่ไม่ใช่ผู้เล่น) วิธีนี้จะทำงานได้เฉพาะใน Humanoids ที่มี Player ที่เหมาะสมเนื่องจากต้องมีวัตถุ Backpack เพื่อเป็นพ่อของ Tool ที่ไม่ได้ติดตั้ง

ดูเพิ่ม:


ส่งค่ากลับ

()

ตัวอย่างโค้ด

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.

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

วิธีนี้จะได้รับการปรับปรุงผ่านการสร้างสมมติฐานว่าเฉพาะวิธีนี้เท่านั้นที่ใช้เพื่อเปลี่ยนรูปลักษณ์ของตัวละครและไม่มีการเปลี่ยนแปลงผ่านวิธีการอื่นระหว่างการโทรหากมีการเปลี่ยนแปลงตัวละครระหว่างการโทร วิธีนี้อาจไม่ทำให้ตัวละครสะท้อนถึงสิ่งที่ส่งมาใน HumanoidDescription อย่างถูกต้องหากคุณต้องการใช้วิธีนี้ร่วมกับวิธีอื่นในการอัปเดตตัวละคร Humanoid:ApplyDescriptionReset() จะมั่นใจเสมอว่าตัวละครสะท้อนสิ่งที่ส่งมาใน HumanoidDescription

ดูเพิ่มเติม

พารามิเตอร์

humanoidDescription: HumanoidDescription

ตัวอย่าง HumanoidDescription ตรงกัน

ค่าเริ่มต้น: ""
assetTypeVerification: Enum.AssetTypeVerification
ค่าเริ่มต้น: "Default"

ส่งค่ากลับ

()

ApplyDescriptionReset

()
ผลตอบแทน

วิธียอมแพ้นี้ทำให้ลักษณะของตัวละครสอดคล้องกับที่ส่งใน HumanoidDescription แม้หลังจากการเปลี่ยนแปลงภายนอกสำเนาของการส่งผ่าน HumanoidDescription ถูกบันทึกไว้ในคลังเป็น HumanoidDescription สำหรับ Humanoid

วิธีนี้จะมั่นใจเสมอว่าตัวละครสะท้อนสิ่งที่ส่งมาใน HumanoidDescription แม้ว่าจะมีการเปลี่ยนแปลงในตัวละครที่ไม่ใช้ระบบ HumanoidDescription (ตัวอย่างเช่นไม่ใช้ ApplyDescriptionReset() หรือ ApplyDescription() )นี้แตกต่างจาก ApplyDescription() ซึ่งได้รับการปรับให้เหมาะสมและอาจใช้ HumanoidDescription ไม่ถูกต้องหากตัวละครได้รับการเปลี่ยนแปลงโดยวิธีอื่นนอกเหนือจากผ่านระบบ HumanoidDescription

พารามิเตอร์

humanoidDescription: HumanoidDescription

ตัวอย่าง HumanoidDescription ที่คุณต้องการตั้งค่าตัวละครให้ตรงกัน

ค่าเริ่มต้น: ""
assetTypeVerification: Enum.AssetTypeVerification
ค่าเริ่มต้น: "Default"

ส่งค่ากลับ

()

PlayEmote

ผลตอบแทน

หากอีโมทไม่สามารถเล่นได้เพราะชื่ออีโมทไม่พบในคำอธิบาย Humanoid วิธีนี้จะให้ข้อผิดพลาดวิธีนี้จะส่งคืนค่าเป็นจริงเพื่อระบุว่าอีโมทถูกเล่นสําเร็จ

พารามิเตอร์

emoteName: string

ชื่อของอีโมทที่จะเล่น

ค่าเริ่มต้น: ""

ส่งค่ากลับ

เล่นได้สำเร็จ

อีเวนต์

ApplyDescriptionFinished

พารามิเตอร์

description: HumanoidDescription

Climbing

ไฟเมื่อความเร็วที่ Humanoid กําลังปีนเปลี่ยนแปลง

Humanoids สามารถปีนบันไดที่ทำจาก Parts หรือ TrussParts ได้

Humanoids ปีนที่ 70% ของพวกเขา Humanoid.WalkSpeed .

อีเวนต์นี้จะไม่เกิดขึ้นเสมอด้วยความเร็ว 0 เมื่อ Humanoid หยุดปีน

ดูเพิ่ม:

  • สำหรับการว่ายน้ำและการวิ่งดูกิจกรรม Humanoid.Swimming และ Humanoid.Running
  • คุณยังสามารถตรวจสอบได้เมื่อ Humanoid กําลังปีนขึ้นโดยใช้อีเวนต์ Humanoid.StateChanged
  • คุณสามารถปิดการปีนโดยใช้ฟังก์ชัน Humanoid:SetStateEnabled()

พารามิเตอร์

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 หรือกำหนดค่าสถานะโดยตรง

อีเวนต์นี้จะยิงเฉพาะถ้า เป็นลูกหลานของ หาก ถูกปิดใช้งานจะไม่ยิง


ตัวอย่างโค้ด

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.

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

อีเวนต์ FallingDown จะเกิดขึ้นเมื่อ Humanoid เข้าและออกจาก FallingDown``Enum.HumanoidStateType

The Humanoid จะเข้าสู่สถานะ GettingUp หลังจากสถานะ FallingDown ถูกเปิดใช้งาน 3 วินาทีเมื่อเกิดเหตุนี้ขึ้นอีเวนต์จะยิงด้วยค่า ที่ใช้งาน ของ ปลอม และ Humanoid.GettingUp จะยิงด้วยค่า ที่ใช้งาน ของ จริง

พารามิเตอร์

active: boolean

อธิบายว่า Humanoid กำลังเข้าสู่หรือออกจาก FallingDown``Enum.HumanoidStateType


FreeFalling

อีเวนต์นี้จะเกิดขึ้นเมื่อ Humanoid เข้าหรือออกจาก Freefall``Enum.HumanoidStateType

พารามิเตอร์ที่ใช้งาน เป็นตัวแทนว่า กำลังเข้าสู่หรือออกจากสถานะ

แม้ว่าสถานะ Freefall จะสิ้นสุดเมื่อ Humanoid ไปถึงพื้น แต่อีเวนต์นี้อาจจะเกิดขึ้นได้เมื่อ active เท่ากับ false หากสถานะเปลี่ยนแปลงในขณะที่ Humanoid กำลังลดลงด้วยเหตุผลนี้คุณควรใช้ Humanoid.StateChanged และฟังสถานะ Landed เมื่อมีการลงจอด Humanoid

พารามิเตอร์

active: boolean

ว่า Humanoid กำลังเข้าหรือออกจาก Freefall``Enum.HumanoidStateType .


GettingUp

อีเวนต์นี้จะเกิดขึ้นเมื่อ Humanoid เข้าหรือออกจากสถานะ Enum.HumanoidStateType.GettingUp สถานะเปลี่ยนผ่านที่เปิดใช้งานในไม่ช้าหลังจากที่ Humanoid เข้าสู่สถานะ FallingDown (3 วินาที) หรือ Ragdoll (1 วินาที) สถานะ

เมื่อ Humanoid พยายามที่จะลุกขึ้นอีกครั้ง อีเวนต์นี้จะยิงก่อนด้วยพารามิเตอร์ active ของ true ก่อนที่จะยิงอีกครั้งด้วยพารามิเตอร์ active ในไม่ช้าหลังจากยิงอีกครั้งด้วยพารามิเตอร์ false

เพื่อบังคับให้ Humanoid ตกลงมา ให้ใช้ฟังก์ชัน Humanoid:ChangeState() ด้วย Enum.HumanoidStateType.FallingDown

พารามิเตอร์

active: boolean

ว่า Humanoid กำลังเข้าหรือออกจาก GettingUp``Enum.HumanoidStateType .


HealthChanged

อีเวนต์นี้จะเกิดขึ้นเมื่อมีการเปลี่ยนแปลง Humanoid.Healthอย่างไรก็ตาม มันจะไม่ยิงหากสุขภาพเพิ่มขึ้นจากค่าที่เท่ากับหรือมากกว่า Humanoid.MaxHealth

เมื่อ Humanoid.Health ถึงศูนย์ การเหตุการณ์ Humanoid จะตายและการเหตุการณ์ Humanoid.Died จะเกิดขึ้น อีเวนต์นี้จะเกิดขึ้นด้วยค่าเป็นศูนย์

พารามิเตอร์

health: number

ค่าใหม่ของ Humanoid.Health .


ตัวอย่างโค้ด

The following example determines the change in health, printing it to the output. It will only work in a LocalScript.

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)

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.

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

เมื่อกระโดด Humanoid จะเกิดเหตุการณ์นี้ขึ้นพร้อมกับพารามิเตอร์ active ของ true ก่อนที่จะยิงอีกครั้งในภายหลังด้วยพารามิเตอร์ active ของ falseการยิงครั้งที่สองนี้ไม่ตรงกับการลงจอด Humanoid สำหรับเรื่องนั้น ให้ฟังสำหรับ Landed``Enum.HumanoidStateType โดยใช้ Humanoid.StateChanged .

คุณสามารถปิดการกระโดดโดยใช้ฟังก์ชัน Humanoid:SetStateEnabled() ได้

พารามิเตอร์

active: boolean

ว่า Humanoid กำลังเข้าหรือออกจาก Jumping``Enum.HumanoidStateType .


MoveToFinished

อีเวนต์นี้จะเกิดขึ้นเมื่อ Humanoid เสร็จสิ้นการเดินไปยังเป้าหมายที่ประกาศโดย Humanoid.WalkToPoint และ Humanoid.WalkToPart คุณสมบัติ

คุณสมบัติ Humanoid.WalkToPoint และ Humanoid.WalkToPart สามารถตั้งค่าได้เองหรือโดยใช้ฟังก์ชัน Humanoid:MoveTo()

หาก Humanoid ถึงเป้าหมายภายใน 8 วินาที อีเวนต์นี้จะกลับมาพร้อมกับ ได้ถึง เป็นจริงหากเป้าหมายไม่ถูกบรรลุภายใน 8 วินาที Humanoid จะหยุดเดินและ ถึง จะเป็นเท็จคุณสามารถรีเซ็ตเวลาหมดอายุนี้ได้โดยการโทร Humanoid:MoveTo() อีกครั้งภายในระยะเวลาหมดอายุ

พารามิเตอร์

reached: boolean

บูลีนที่บ่งบอกว่า Humanoid ถึงเป้าหมายหรือไม่ถูกต้อง หาก Humanoid ถึงเป้าหมายของมันแล้ว ไม่ถูกต้อง หากการเดินทางหมดเวลาก่อนที่จะบรรลุเป้าหมาย


ตัวอย่างโค้ด

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.

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

อีเวนต์นี้จะเกิดขึ้นเมื่อ Humanoid เข้าหรือออกจาก PlatformStanding``Enum.HumanoidStateType

ในขณะที่ Humanoid อยู่ในสถานะ PlatformStanding คุณสมบัติ Humanoid.PlatformStand จะเป็น จริง

ในขณะที่ Humanoid.PlatformStand ถูกตั้งค่าเป็น true แต่ Humanoid จะไม่สามารถย้ายได้ สำหรับข้อมูลเพิ่มเติมโปรดดูที่หน้าสำหรับ Humanoid.PlatformStand

แพลตฟอร์มสแตนด์ Enum.HumanoidStateType ถูกเชื่อมโยงกับส่วนที่ถูกปิดใช้งานแล้ว Platform แม้ว่าจะเป็นเช่นนั้น แต่ก็ยังสามารถใช้งานโดยนักพัฒนาได้

พารามิเตอร์

active: boolean

ว่า Humanoid กำลังเข้าหรือออกจาก PlatformStanding``Enum.HumanoidStateType .


Ragdoll

อีเวนต์นี้จะเกิดขึ้นเมื่อ Humanoid เข้าหรือออกจาก Ragdoll``Enum.HumanoidStateType

พารามิเตอร์ active จะมีค่า true หรือ false เพื่อระบุการเข้าหรือออก

ใช้ Humanoid:SetStateEnabled() เพื่อปิดใช้งานสถานะ GettingUp เพื่ออยู่ในสถานะ Ragdoll

ดูเพิ่ม:

  • Humanoid.FallingDown สำหรับอีเวนต์ Humanoid ที่เชื่อมต่อกับสถานะ FallingDown ซึ่งมีพฤติกรรมคล้ายกับ Ragdoll

พารามิเตอร์

active: boolean

ว่า Humanoid กำลังเข้าหรือออกจาก Ragdoll``Enum.HumanoidStateType .


Running

อีเวนต์นี้จะเกิดขึ้นเมื่อความเร็วที่ Humanoid กำลังดำเนินการเปลี่ยนแปลง

ในขณะที่เรียกใช้ Humanoids ครอบคลุม เฉลี่ยแล้ว ของพวกเขา Humanoid.WalkSpeed ในสตัดต่อวินาที

เมื่อ Humanoid หยุดการทำงานของอีเวนต์นี้จะยิงด้วยความเร็ว 0

ดูเพิ่ม:

  • สำหรับการว่ายน้ำและปีนเขาดูกิจกรรม Humanoid.Swimming และ Humanoid.Climbing
  • คุณยังสามารถตรวจสอบได้เมื่อ Humanoid กําลังดําเนินการโดยใช้อีเวนต์ Humanoid.StateChanged

พารามิเตอร์

speed: number

ความเร็วที่ Humanoid กำลังทำงาน


ตัวอย่างโค้ด

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.

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 จะเป็น ปิด และ currentSeatPart จะเป็น nil

ดูเพิ่ม:

  • Humanoid.Sit ซึ่งบ่งบอกถึงว่ามนุษย์หุ่นยนต์กําลังนั่งอยู่ในขณะนี้
  • Humanoid.SeatPart ซึ่งบ่งบอกถึงที่นั่งที่มนุษย์หุ่นยนต์กําลังนั่งอยู่ในปัจจุบัน ถ้ามี

พารามิเตอร์

active: boolean

ถูกหาก Humanoid นั่งลง

currentSeatPart: BasePart

ที่นั่ง Humanoid จะนั่งถ้ามันนั่งลง


ตัวอย่างโค้ด

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.

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 ยืนนิ่ง

ดูเพิ่มเติม

พารามิเตอร์

พิมพ์

พิมพ์


ตัวอย่างโค้ด

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.

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)

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.

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

อีเวนต์ StateEnableChanged จะเกิดขึ้นเมื่อ Humanoid:SetStateEnabled() ถูกเรียกใน Humanoid

พารามิเตอร์รวมถึง Enum.HumanoidStateType ในคำถามพร้อมกับบูลที่ระบุว่าสถานะนี้เปิดใช้งานแล้วหรือไม่

ดูเพิ่ม:

  • เพื่อค้นหาว่าสถานะมีการเปิดใช้งานในปัจจุบันหรือไม่ใช้ Humanoid:GetStateEnabled()
  • เพื่อฟังการเปลี่ยนแปลงสถานะ Humanoid ใช้ Humanoid.StateChanged

พารามิเตอร์

The Enum.HumanoidStateType สำหรับซึ่งสถานะที่เปิดใช้งานได้เปลี่ยนแปลงไป

isEnabled: boolean

ถูกหากสถานะถูกเปิดใช้งานแล้ว


ตัวอย่างโค้ด

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.

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 ถูกโจมตีและไม่ควรใช้โดยนักพัฒนา

อีเวนต์นี้จะถูกกระตุ้นเมื่อ Humanoid เข้าหรือออกจาก StrafingNoPhysics``Enum.HumanoidStateType

เมื่อ Humanoid เข้าสู่สถานะ StrafingNoPhysics อีเวนต์นี้จะยิงด้วยพารามิเตอร์ ใช้งาน ของ trueอีเวนต์จะยิงอีกครั้งด้วย ใช้งาน เท่ากับ ปิด เมื่อ Humanoid ออกจากสถานะ StrafingNoPhysics

อีเวนต์นี้เกี่ยวข้องกับสถานะ และไม่ได้ยิงเมื่อ เคลื่อนที่ตั้งฉากกับทิศทางที่มันกำลังเผชิญอยู่สถานะนี้ขณะนี้ไม่ได้ใช้งานหากตั้งค่าโดยใช้ Humanoid:ChangeState() สถานะจะกลับไปเป็น RunningNoPhysics

พารามิเตอร์

active: boolean

ว่า Humanoid กำลังเข้าหรือออกจาก StrafingNoPhysics``Enum.HumanoidStateType .


Swimming

อีเวนต์นี้จะเกิดขึ้นเมื่อความเร็วที่ Humanoid ว่ายน้ําใน Terrain น้ําเปลี่ยนแปลง

Humanoids ว่ายน้ําที่ 87.5% ของพวกเขา Humanoid.WalkSpeed .

อีเวนต์นี้จะไม่เกิดขึ้นเสมอด้วยความเร็ว 0 เมื่อ Humanoid หยุดว่ายน้ำ

ดูเพิ่ม:

  • สำหรับการวิ่งและปีนเขาดูกิจกรรม Humanoid.Running และ Humanoid.Climbing
  • คุณยังสามารถตรวจจับเมื่อ Humanoid ว่ายน้ําโดยใช้อีเวนต์ Humanoid.StateChanged
  • คุณสามารถปิดการว่ายน้ําโดยใช้ฟังก์ชัน Humanoid:SetStateEnabled()

พารามิเตอร์

speed: number

ความเร็วที่ Humanoid กําลังว่ายอยู่ในปัจจุบัน


Touched

อีเวนต์นี้จะเกิดขึ้นเมื่อหนึ่งในขาของหุ่นยนต์มาสัมผัสกับอีก BasePart คนสิ่งที่ BasePart ซึ่งแขนกำลังสัมผัสอยู่ร่วมกับแขนเองจะได้รับ

อีเวนต์นี้จะไม่เกิดขึ้นเมื่อส่วนที่เป็นของ Humanoid มาสัมผัสกับตัวเอง

ทางเลือก

แม้ว่าอีเวนต์ Humanoid.Touched จะมีประโยชน์ แต่คุณควรพิจารณาว่ามีทางเลือกที่เหมาะสมกับความต้องการของคุณหรือไม่

  • ในกรณีส่วนใหญ่แนะนำให้เชื่อมต่ออีเวนต์ BasePart.Touched สำหรับ BaseParts ที่สนใจแทนเนื่องจากอีเวนต์ Humanoid.Touched จะเปิดตลอดเวลาเมื่อมนุษย์หุ่นยนต์เคลื่อนที่ตัวอย่างเช่นในเกมดอดจ์บอลจะเป็นการเป็นประโยชน์มากขึ้นที่จะเชื่อมต่ออีเวนต์ Touched สำหรับลูกบอลแทนที่จะใช้ Humanoid.Touched
  • เมื่อพยายามทำงานเมื่อ Humanoid ได้ลงจอดบนพื้นแล้ว อีเวนต์ Humanoid.StateChanged เหมาะสมยิ่งขึ้นหรือคุณสามารถตรวจสอบ Humanoid.FloorMaterial เพื่อดูว่ามนุษย์หุ่นยนต์ยืนอยู่บนวัสดุที่ไม่ใช่อากาศ

บันทึก

  • การเชื่อมต่อกับอีเวนต์นี้จะทําให้ TouchTransmitter ถูกสร้างขึ้นในทุกส่วน
  • ขณะนี้ไม่มีตัวเทียบเท่าของ BasePart.TouchEnded สำหรับ Humanoids

พารามิเตอร์

touchingPart: BasePart

The BasePart ที่ Humanoid ได้มาในการติดต่อ

humanoidPart: BasePart

แขนงของ 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.

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)