휘두르기
Coddy의 Roblox 게임: 배틀그라운드 코스 레슨. 25개 중 2번째.
도구를 손에 들고 클릭(또는 탭)하면 서버에서도 Tool의 Activated 이벤트가 발생합니다. 휘두를 때 Roblox 자체의 검 휘두르기 동작을 재생합니다. Animation은 ID로 애니메이션을 지정하고, Humanoid 안에 있는 캐릭터의 Animator가 애니메이션을 트랙에 불러와 재생합니다.
local slash = Instance.new("Animation")
slash.AnimationId = "rbxassetid://522635514"
character.Humanoid.Animator:LoadAnimation(slash):Play()제한이 없으면 플레이어는 원하는 만큼 빠르게 클릭할 수 있으므로, 휘두를 때마다 플레이어별로 테이블에 마지막 휘두른 시점을 기록하고 Settings.SwingCooldown초 안에는 다시 휘두르지 못하게 합니다.
챌린지
쉬움클릭해서 검을 휘두르세요.
- 위쪽 근처에
local lastSwing = {}와slash애니메이션, IDrbxassetid://522635514를 추가하세요. swing(player)를 작성하세요. 캐릭터가 죽었거나Settings.SwingCooldown보다 짧은 시간이 지난 뒤 휘둘렀다면 반환하세요.- 그렇지 않으면
lastSwing[player] = now를 설정하고character.Humanoid.Animator에서 베기 애니메이션을 재생하세요. - 검의
Activated를swing(player)에 연결하세요.
‘플레이’를 누르고, 검을 든 채 클릭하세요. 캐릭터가 검을 휘두릅니다. 그런 다음 ‘확인’을 누르세요.
직접 해보기
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Settings = require(game.ReplicatedStorage.Settings)
print("Swords deal " .. Settings.SwordDamage .. " damage")
-- 레슨 2: 여기에 Swing을 넣습니다
-- 모든 플레이어는 생명마다 검을 하나씩 받습니다
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local sword = ServerStorage.Sword:Clone()
sword.Parent = player.Backpack
end)
end)
Roblox 게임: 배틀그라운드의 모든 레슨
직접 연습해 보세요: Roblox 플레이그라운드