Q 키로 대시하기
Coddy의 Roblox 게임: 배틀그라운드 코스 레슨. 25개 중 7번째.
대시는 밀어내기입니다. 루트의 AssemblyLinearVelocity를 설정하면 캐릭터가 튕겨 나갑니다. 하지만 Roblox에서는 각 플레이어의 기기가 자신의 캐릭터 물리를 실행하므로, 서버에서 설정한 밀어내기는 캐릭터를 거의 움직이지 못합니다. 서버가 결정하고, 플레이어 자신의 LocalScript가 밀어냅니다.
서버는 능력을 이름별로 테이블에 저장하며, 대시가 승인되면 FireClient를 사용해 해당 플레이어의 클라이언트로 전달하고, 클라이언트는 OnClientEvent로 이를 받습니다.
remotes.Ability.OnClientEvent:Connect(function(name)
if name == "Hop" then
root.AssemblyLinearVelocity = Vector3.new(0, 50, 0)
end
end)챌린지
중급Q 대시를 구현하세요. 서버가 승인하면 기기가 밀어냅니다.
BattleServer에서 print를abilities테이블로 바꾸세요.abilities.Dash(player)는remotes.Ability:FireClient(player, "Dash")를 호출합니다.- 핸들러는 해당 항목이 있으면
abilities[name](player, character, root)를 실행합니다. BattleClient에서remotes.Ability.OnClientEvent가"Dash"를 받으면, 루트의 속도를root.CFrame.LookVector * Settings.DashSpeed + Vector3.new(0, 15, 0)로 설정하세요.
‘플레이’를 누르고 Q를 누르세요. 앞으로 대시합니다. 그런 다음 ‘확인’을 누르세요.
직접 해보기
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 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()
-- 앞쪽 상자 범위에 자신의 몸은 포함되지 않음
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
humanoid:TakeDamage(Settings.SwordDamage)
print(humanoid.Parent.Name .. " is at " .. humanoid.Health)
end
end
end
-- 클라이언트가 이름으로 능력 사용을 요청함
remotes.Ability.OnServerEvent:Connect(function(player, name)
print(player.Name .. " asked for " .. name)
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 플레이그라운드