폭발은 explosion(로블록스 내 이미 정의된 클래스)의 Explosion.BlastRadius안에 있는 BasePart들에 힘을 가하게 된다. 즉, Explosion.BlastRadius 반경에 있는 (보통 경우)캐릭터들에 포스를 가해서 관절을 끊어 버리고 캐릭터는 죽여 버리게 된다. ForceField에 의해서 보호되고 있는 캐릭터는 물론 살 수 있다.
게임이 실행되는 동안 폭발 이펙트를 발생시키면 곧 자체적으로 Destory되므로 Debris 서비스를 사용하여 리소스를 지울 필요가 없다.
폭발 이펙트(Explosion effects)
휴머노이드는 캐릭터 모델의 목 관절이 부러지면서 폭발로 사망합니다. 포스필드에 의해 보호되는 모든 파트는 폭발로부터 보호되는데 이 말은 파트의 관절이 부러지지 않아서 휴머노이드가 죽지 않게 된다는 말이다.
만약에 개발자가 관절을 부러뜨리지 않고 어떤 공식에 의해서 휴머노이드에게 데미지를 주고 싶다면, Explosion.DestoryJointRadiusPercent 를 0으로 설정하고 Explosion.Hit 이벤트를 사용하여 폭발의 결과를 코드로 처리하면 된다.
폭발은 지형(Terrain)을 손상시켜서 크레이터(Craters)를 생성하게 만들 수도 있다. Explosion/ExplosionType 속성을 살펴보자.
폭발의 효과는 장애물에 의해 방해받지 않는다. 즉, 다른 파트 뒤에 숨겨져 있는 파트도 영향을 받는다는 말이다. 폭발이 장애물에 의해 블록되는 효과를 얻기 위해서는 따로 Explosion.Hit의 이벤트를 사용하여 스크립트를 만들어야 할 것이다.
Explosion Instantiation
게임에서 (0, 10, 0) 포지션에 큰 폭발을 일으키는 간단한 소스 코드
local explosion = Instance.new("Explosion")
-- 폭발 이펙트 크기 60
explosion.BlastRadius = 60
-- 지형에 크레이터를 남기고 싶다.
explosion.ExplosionType = Enum.ExplosionType.Craters
-- 위치는 (0, 10, 0)
explosion.Position = Vector3.new(0, 10, 0)
-- 월드 포지션
explosion.Parent = game.Workspace
- Creating the Pack
- Touch Event
- Healing Code
- Cooldown
- Finishing Touches
- Max Health Check
- Cooldown Indication
- Single-Use Pack
Health PickupsTAGS:
- pickup
- health
- boost
- Related Articles
- Making an Explosion Course
- In this article, we’ll explore collision handling and player stats to create health packs which players can walk over to heal themselves.The health pack itself can be a mesh, group of parts (Model), solid-modeled object, or even a simple Part. Whatever type you choose:
- Anchor the object so players can’t kick it around.
- Insert a Script as a direct child of the object (if you’re using a group of parts, insert the script as a child of the health pack’s “case” since we’ll use it for collision detection).
- COPY CODELIGHT THEME
-
- local healthPack = script.Parent
- local healAmount = 30
- local function onPartTouch(otherPart)
- local partParent = otherPart.Parent
- local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
- if humanoid and humanoid.Health < humanoid.MaxHealth then
- -- Player character touched health pack
- local currentHealth = humanoid.Health
- local newHealth = currentHealth + healAmount
- humanoid.Health = newHealth
- healthPack:Destroy()
- end
- end
- healthPack.Touched:Connect(onPartTouch)
- COPY CODELIGHT THEME
-
- local function onPartTouch(otherPart)
- local partParent = otherPart.Parent
- local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
- if humanoid and canHeal == true and humanoid.Health < humanoid.MaxHealth then
- -- Player character touched health pack
- canHeal = false
- local currentHealth = humanoid.Health
- local newHealth = currentHealth + healAmount
- humanoid.Health = newHealth
- healthPack.Transparency = 0.6
- wait(cooldown)
- healthPack.Transparency = 0
- canHeal = true
- end
- end
- healthPack.Touched:Connect(onPartTouch)
- Single-Use Pack
- If you don’t want a multi-use health pack — for example, if you want to store the pack in ServerStorage and clone copies to the game world for one-time usage — just remove all of the cooldown logic and add a Destroy() command after the healing code:
- COPY CODELIGHT THEME
-
- local function onPartTouch(otherPart)
- local partParent = otherPart.Parent
- local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
- if humanoid and canHeal == true and humanoid.Health < humanoid.MaxHealth then
- -- Player character touched health pack
- canHeal = false
- Cooldown Indication
- A visual indication during the pack’s cooldown period will inform players that it can’t currently be collected. If your health pack is a single mesh or object (not a group of objects), you can simply increase its Transparency during the cooldown period and reset it afterwards:
- COPY CODELIGHT THEME
-
- local function onPartTouch(otherPart)
- local partParent = otherPart.Parent
- local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
- if humanoid and canHeal == true then
- -- Player character touched health pack
- canHeal = false
- local currentHealth = humanoid.Health
- local newHealth = currentHealth + healAmount
- humanoid.Health = newHealth
- wait(cooldown)
- canHeal = true
- end
- end
- healthPack.Touched:Connect(onPartTouch)
- Finishing TouchesMax Health Check
- The pack shouldn’t heal characters who are already at full health, so let’s add another condition which checks if the player’s health is below the max amount:
- The health pack is now functional but a few additions will make it even better.
- COPY CODELIGHT THEME
-
- local healthPack = script.Parent
- local healAmount = 30
- local cooldown = 10
- local canHeal = true
- Now, in the conditional statement that checks for a Humanoid, test whether canHeal is true. If it is, set it to false so the healing code won’t immediately execute again. After the character is healed, wait for the duration of cooldown and then set canHeal back to true:
- COPY CODELIGHT THEME
-
- local healthPack = script.Parent
- local healAmount = 30
- local function onPartTouch(otherPart)
- local partParent = otherPart.Parent
- local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
- if humanoid then
- -- Player character touched health pack
- local currentHealth = humanoid.Health
- local newHealth = currentHealth + healAmount
- humanoid.Health = newHealth
- end
- end
- healthPack.Touched:Connect(onPartTouch)
- Cooldown
- At this point, the Touched event will continue to fire when any part of the character — foot, hand, leg, etc. — touches the health pack, potentially boosting the player’s health by much more than 30. To fix this, first create a cooldown variable, representing how many seconds the health pack’s “cooldown” will last, and canHeal as a boolean for whether the pack can heal:
- Healing Code
- By default, Roblox characters have 100 health, so let’s create a healAmount variable set to 30. We can then use the Humanoid.Health property to add health to the player that touched the pack.
- Touch Event
- Creating the Pack
- EXPAND
- COPY CODELIGHT THEME
-
- local healthPack = script.Parent
- local function onPartTouch(otherPart)
- local partParent = otherPart.Parent
- local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
- if humanoid then
- -- Player character touched health pack
- end
- end
- healthPack.Touched:Connect(onPartTouch)
- 10 min
'로블록스 개발 중급' 카테고리의 다른 글
Blaster 제작 : 서버/클라이언트 이벤트 처리(3/3) (1) | 2021.08.05 |
---|---|
플레이어의 키입력 처리하기 (1) | 2021.08.03 |
CFrame 이해하기 (0) | 2021.06.04 |
로블록스 중급 목차 (1) | 2021.05.28 |
게임에서 직접 만든 커스텀 애니메이션 사용하기 (1) | 2021.05.28 |