넉백
Coddy의 Roblox 게임: 배틀그라운드 코스 레슨. 25개 중 11번째.
강타하면 맞은 대상을 날려 보내야 합니다. 루트에 ApplyImpulse를 적용하면 몸 전체에 힘을 줍니다. 충격량은 질량에 속도 변화를 곱한 값이므로, AssemblyMass를 곱하면 가벼운 리그와 무거운 리그를 같은 방식으로 날려 보낼 수 있습니다.
theirRoot:ApplyImpulse((away * 30 + Vector3.new(0, 20, 0)) * theirRoot.AssemblyMass)away는 지면을 따라 당신에게서 상대방을 향하는 방향을 가리킵니다. 즉, 상대방의 위치에서 당신의 위치를 뺀 뒤 Y를 0으로 만들고, 길이가 1이 되도록 .Unit을 적용합니다.
챌린지
중급강타에 맞은 모든 대상이 날아가게 만드세요.
abilities.Slam에서hurt다음에 다음을 추가하세요:local away = (theirRoot.Position - root.Position) * Vector3.new(1, 0, 1). 그런 다음 Magnitude가 0보다 크면away = away.Unit을 실행하세요.- 그다음
theirRoot:ApplyImpulse((away * Settings.SlamKnockback + Vector3.new(0, 40, 0)) * theirRoot.AssemblyMass)를 실행하세요.
‘플레이’를 누르고, 빨간색 리그 두 개 사이를 걸어가 E를 누르세요. 리그들이 서로 날아갑니다. 그런 다음 ‘확인’을 누르세요.
직접 해보기
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
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
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)
-- 11과: 밀쳐내기 기능은 여기에 추가합니다
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 플레이그라운드