본문 바로가기

로블록스 개발 중급

(로블록스)폭발 이펙트 만들기

폭발은 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

 Hide content

  • 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:
      1. Anchor the object so players can’t kick it around.
      2. 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).
      For a basic health pack, any player that touches it should get healed, so the script needs a Touched event. In the function that’s triggered by the event, we need to confirm that whatever touched the health pack is a player character (otherwise the health pack will try to heal anything it comes in contact with). To achieve this, we’ll check if the parent object that touched the health pack contains a Humanoid, a special Instance that’s part of all player characters.EXPAND EXPAND EXPAND EXPAND EXPAND EXPAND 
    •  COPY CODELIGHT THEME 
      1. local healthPack = script.Parent
      2. local healAmount = 30
      3.  
      4. local function onPartTouch(otherPart)
      5. local partParent = otherPart.Parent
      6. local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
      7. if humanoid and humanoid.Health < humanoid.MaxHealth then
      8. -- Player character touched health pack
      9. local currentHealth = humanoid.Health
      10. local newHealth = currentHealth + healAmount
      11. humanoid.Health = newHealth
      12. healthPack:Destroy()
      13. end
      14. end
      15. healthPack.Touched:Connect(onPartTouch)
    •  COPY CODELIGHT THEME 
      1. local function onPartTouch(otherPart)
      2. local partParent = otherPart.Parent
      3. local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
      4. if humanoid and canHeal == true and humanoid.Health < humanoid.MaxHealth then
      5. -- Player character touched health pack
      6. canHeal = false
      7. local currentHealth = humanoid.Health
      8. local newHealth = currentHealth + healAmount
      9. humanoid.Health = newHealth
      10. healthPack.Transparency = 0.6
      11. wait(cooldown)
      12. healthPack.Transparency = 0
      13. canHeal = true
      14. end
      15. end
      16. 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 
      1. local function onPartTouch(otherPart)
      2. local partParent = otherPart.Parent
      3. local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
      4. if humanoid and canHeal == true and humanoid.Health < humanoid.MaxHealth then
      5. -- Player character touched health pack
      6. 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 
      1. local function onPartTouch(otherPart)
      2. local partParent = otherPart.Parent
      3. local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
      4. if humanoid and canHeal == true then
      5. -- Player character touched health pack
      6. canHeal = false
      7. local currentHealth = humanoid.Health
      8. local newHealth = currentHealth + healAmount
      9. humanoid.Health = newHealth
      10. wait(cooldown)
      11. canHeal = true
      12. end
      13. end
      14. 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 
      1. local healthPack = script.Parent
      2. local healAmount = 30
      3. local cooldown = 10
      4. 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 
      1. local healthPack = script.Parent
      2. local healAmount = 30
      3.  
      4. local function onPartTouch(otherPart)
      5. local partParent = otherPart.Parent
      6. local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
      7. if humanoid then
      8. -- Player character touched health pack
      9. local currentHealth = humanoid.Health
      10. local newHealth = currentHealth + healAmount
      11. humanoid.Health = newHealth
      12. end
      13. end
      14. 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 
      1. local healthPack = script.Parent
      2.  
      3. local function onPartTouch(otherPart)
      4. local partParent = otherPart.Parent
      5. local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
      6. if humanoid then
      7. -- Player character touched health pack
      8.  
      9. end
      10. end
      11. healthPack.Touched:Connect(onPartTouch)
    • 10 min