Menu
CoddyTech

히트박스

Coddy의 Roblox 게임: 배틀그라운드 코스 레슨. 20개 중 3번째.

휘두른 검은 무언가에 맞아야 합니다. "내 앞에 무엇이 있지?"는 공간 쿼리입니다. workspace:GetPartBoundsInBox는 상자(중심을 나타내는 CFrame과 크기를 나타내는 Vector3)를 받아 그 상자와 겹치는 모든 파트를 반환합니다.

local box = root.CFrame * CFrame.new(0, 0, -3) -- 앞쪽으로 3 studs
local parts = workspace:GetPartBoundsInBox(box, Settings.HitboxSize, params)

파트의 모델에는 Humanoid가 있으므로, part.Parent:FindFirstChildOfClass("Humanoid")를 사용하면 그 파트가 피해를 입을 수 있는 대상에게 속하는지 알 수 있습니다.

자신의 팔도 그 상자 안에 들어갑니다. OverlapParams로 쿼리를 필터링하세요. 캐릭터를 FilterDescendantsInstances에 넣으면 상자에 자신의 신체가 검색되지 않습니다.

challenge icon

챌린지

쉬움

swing의 끝에서:

  1. 플레이어 캐릭터를 제외하는 OverlapParams를 만드세요.
  2. 루트 앞쪽 3 스터드에 있고 Settings.HitboxSize 크기인 상자의 GetPartBoundsInBox에 있는 모든 파트에 대해: 해당 파트의 부모에 Humanoid가 있으면 TakeDamage(Settings.SwordDamage)를 실행하세요.

Play를 누르고 훈련용 더미를 공격하세요. 그런 다음 Check를 누르세요.

직접 해보기

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Settings = require(game.ReplicatedStorage.Settings)

local lastSwing = {} -- player -> 마지막으로 검을 휘두른 시각

-- Roblox의 기본 검 애니메이션
local slash = Instance.new("Animation")
slash.AnimationId = "rbxassetid://522635514"

print("Swords deal " .. Settings.SwordDamage .. " damage")

-- 검 휘두르기: SwingCooldown마다 최대 한 번 애니메이션 재생
local function swing(player)
	local character = player.Character
	local root = character and character:FindFirstChild("HumanoidRootPart")
	if not root or character.Humanoid.Health <= 0 then
		return
	end
	local now = time()
	if lastSwing[player] and now - lastSwing[player] < Settings.SwingCooldown then
		return
	end
	lastSwing[player] = now
	character.Humanoid.Animator:LoadAnimation(slash):Play()
end

-- 모든 플레이어는 리더보드에 Kills를 받고, 부활할 때마다 검을 받습니다
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = leaderstats

	player.CharacterAdded:Connect(function()
		local sword = ServerStorage.Sword:Clone()
		sword.Parent = player.Backpack
		sword.Activated:Connect(function()
			swing(player)
		end)
	end)
end)
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

Roblox 게임: 배틀그라운드의 모든 레슨