Menu
CoddyTech

연속 공격

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

연속으로 세 번 휘두르고, 각각 이전 공격 후 Settings.ComboWindow 이내라면 콤보가 됩니다. 공격력은 10, 10, 그다음 돌진 공격은 25입니다(Settings.ComboDamage). 잠시 멈추면 콤보가 초기화됩니다.

서버는 플레이어별로 연속 공격 횟수와 마지막 공격 시점을 기억합니다.

local c = combo[player]
if c and now - c.last <= Settings.ComboWindow then
	c.count = c.count % 3 + 1
else
	c = { count = 1 }
	combo[player] = c
end
c.last = now

c.count % 3 + 1은 1, 2, 3, 1, 2, 3 순서로 진행됩니다. 돌진 공격 후에는 새로운 콤보가 시작됩니다. 세 번째 공격은 Roblox의 돌진 애니메이션인 rbxassetid://522638767을 재생합니다.

challenge icon

챌린지

중급

빠르게 세 번 휘두르면 콤보가 됩니다. 10, 10, 그다음 25의 돌진 공격입니다.

  1. local combo = {}와 ID가 rbxassetid://522638767인 lunge 애니메이션을 추가하세요.
  2. swing에서 재사용 대기 시간 확인 후, 본문에 표시된 대로 휘두른 횟수를 세고 c.last = now로 마무리하세요.
  3. c.count == 3일 때는 돌진 공격 애니메이션을 재생하고, 그렇지 않으면 베기 애니메이션을 재생하세요. Settings.ComboDamage[c.count]로 피해를 주세요.

‘플레이’를 누르고 빠르게 세 번 휘두르세요. 세 번째는 돌진 공격입니다. 그런 다음 ‘확인’을 누르세요.

직접 해보기

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

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

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

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

-- 게임의 모든 타격은 이곳을 거칩니다
local function hurt(humanoid, amount)
	if humanoid.Health <= 0 then
		return
	end
	local character = humanoid.Parent
	-- 방어하면 타격 피해를 대부분 막습니다
	if character:GetAttribute("Blocking") then
		amount *= Settings.BlockMultiplier
	end
	humanoid:TakeDamage(amount)
end

-- 검을 휘두르면 애니메이션이 재생된 뒤 앞쪽 상자 범위 안의 모든 대상이 공격받습니다
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
	-- 레슨 13: 콤보를 여기에 구현합니다
	character.Humanoid.Animator:LoadAnimation(slash):Play()
	-- 앞쪽의 상자 범위이며, 자기 몸은 포함되지 않습니다
	local params = OverlapParams.new()
	params.FilterDescendantsInstances = { character }
	local box = root.CFrame * CFrame.new(0, 0, -3)
	local hit = {} -- 검을 휘두를 때마다 각 humanoid를 한 번씩만 공격합니다
	for _, part in workspace:GetPartBoundsInBox(box, Settings.HitboxSize, params) do
		local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
		if humanoid and not hit[humanoid] then
			hit[humanoid] = true
			hurt(humanoid, Settings.SwordDamage)
		end
	end
end

-- 이름별 능력: 각 능력의 효과
local abilities = {}

-- 플레이어의 캐릭터는 자신의 기기에서 움직이므로 대시도 그곳에서 실행됩니다
function abilities.Dash(player)
	remotes.Ability:FireClient(player, "Dash")
end

-- 주변의 모든 대상이 공격받고 플레이어에게서 멀리 튕겨 나갑니다
function abilities.Slam(player, character, root)
	local params = OverlapParams.new()
	params.FilterDescendantsInstances = { character }
	local hit = {}
	for _, part in workspace:GetPartBoundsInRadius(root.Position, Settings.SlamRadius, params) do
		local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
		local theirRoot = part.Parent:FindFirstChild("HumanoidRootPart")
		if humanoid and theirRoot and not hit[humanoid] then
			hit[humanoid] = true
			hurt(humanoid, Settings.SlamDamage)
			local away = (theirRoot.Position - root.Position) * Vector3.new(1, 0, 1)
			if away.Magnitude > 0 then
				away = away.Unit
			end
			theirRoot:ApplyImpulse((away * Settings.SlamKnockback + Vector3.new(0, 40, 0)) * theirRoot.AssemblyMass)
		end
	end
end

function abilities.Block(player, character)
	character:SetAttribute("Blocking", true)
	task.delay(Settings.BlockTime, function()
		if character.Parent then
			character:SetAttribute("Blocking", nil)
		end
	end)
end

-- 클라이언트가 이름으로 능력 사용을 요청합니다. 서버는 실제로 존재하는
-- 능력이 실제로 존재하는지, 플레이어가 살아 있는지, 재사용 대기 시간이 끝났는지 확인합니다. 다시 사용할 수 있는 시각은
-- 플레이어의 속성으로 저장되어 화면에 표시할 수 있습니다.
remotes.Ability.OnServerEvent:Connect(function(player, name)
	if typeof(name) ~= "string" or not abilities[name] then
		return
	end
	local character = player.Character
	local root = character and character:FindFirstChild("HumanoidRootPart")
	if not root or character.Humanoid.Health <= 0 then
		return
	end
	local now = workspace:GetServerTimeNow()
	if now < (player:GetAttribute(name .. "ReadyAt") or 0) then
		return
	end
	player:SetAttribute(name .. "ReadyAt", now + Settings.Cooldowns[name])
	abilities[name](player, character, root)
end)

-- 모든 플레이어는 부활할 때마다 검을 받습니다
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		local sword = ServerStorage.Sword:Clone()
		sword.Parent = player.Backpack
		sword.Activated:Connect(function()
			swing(player)
		end)
	end)
end)

-- 훈련용 더미: 체력 막대는 체력에 따라 변하고, 쓰러진
-- 더미는 잠시 후 같은 자리에 새 복제본으로 돌아옵니다
local function setupDummy(dummy)
	local humanoid = dummy.Humanoid
	humanoid.HealthChanged:Connect(function(health)
		dummy.HealthBar.Back.Fill.Size = UDim2.fromScale(health / humanoid.MaxHealth, 1)
	end)
	humanoid.Died:Connect(function()
		local spot = dummy:GetPivot()
		task.wait(0.5)
		dummy:Destroy()
		task.wait(Settings.DummyRespawn)
		local fresh = ServerStorage.Dummy:Clone()
		fresh:PivotTo(spot)
		fresh.Parent = workspace
		setupDummy(fresh)
	end)
end
setupDummy(workspace.Dummy)

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

직접 연습해 보세요: Roblox 플레이그라운드