Explosion (Tutorial)

From Legacy Roblox Wiki
Jump to navigationJump to search

Explosions are objects in ROBLOX that are used to create the effect of an explosion.

Creating an explosion

Creating and setting up an explosion is easy. First, you need to create it and put it in the Workspace:

local explosion = Instance.new('Explosion', Workspace)

Then, you need to set its position, which is a Vector3. Supposing we wanted to put the explosion at the position

0
50
0

, we would use the following code:

explosion.Position = Vector3.new(0, 50, 0)

Now, we have an explosion. However, we might also want to set some of its other properties to customize it to our needs.

Explosions have two properties that determine how they act on the physics: BlastPressure and BlastRadius.

The BlastPressure of the explosion determines how powerful it is, how much damage it will do to parts, and how much it will push them away. Its default value is 500,000. It can take integers, but can take decimal numbers too. If this value is really low, the explosion will not push the parts at all, which can be useful to get the effect without affecting the physics at all. However, if you want your explosion to do a lot of damage and to destroy everything in its way, you will have to make the BlastPressure very high. For now, let's say we'll just set it to 500:

explosion.BlastPressure = 500

The BlastRadius is how big the explosion is. Its default value is 4. The bigger this number is, the bigger the explosion will be. If you want a really small explosion, make it small. However, if you want an huge explosion that makes the whole place explode, make it extremly high. Let's set it to 500 too for now:

A crater made by an explosion.
A crater made by an explosion.
explosion.BlastRadius = 500

And that's it, we got a working explosion!

However, we can still customize our explosion a little more.

Explosions have only one property we didn't talk about yet, the ExplosionType property. It is an enum and allows us to set whether we want our explosion to create only craters, only debris, or both. By debris, here, I mean making parts explode, and by craters, I mean making craters in terrain. The enum has three values: Craters, CratersAndDebris, and NoCraters. For now, let's choose CratersAndDebris, to make an explosion that destroys both parts and terrain:

explosion.ExplosionType = Enum.ExplosionType.CratersAndDebris

There, our explosion is fully ready to be used!

Explosions disappear as soon as the effect is done. Where you put them doesn't matter, as soon as it is in the Workspace. However, there is still one thing you don't know about them: they have an event!

The Hit event of explosions fires whenever a part is hit by the explosion and has two arguments:

  • The part that was hit by the explosion.
  • The distance the part flew away when hit by the explosion.

This can be useful to apply a particular effect to every part that got hit by the explosion, for example, adding fire to it and making it black as if it had burnt.

History

Around the time Terrain was created, in 2011, explosions obtained a new property, ExplosionType and a new enum, the ExplosionType enum, was introduced. This made it possible for explosions to make craters in terrain. The default behavior of the explosions was also changed to create craters by default, which it did not do before this update.

In 2011, the explosions were replaced by explosions with a different appearance. The explosions had previously been more orange-like, and more round, but since the update, they are now reddish and seem to try to move higher.[unconfirmed]

Gallery