Hello and welcome to another episode in the Godot Basics tutorial series. Godot Tutorials is not affiliated with or sponsored by Godot Game Engine. In this episode, we will be taking a look at particles, 2D and particles material. But first we must understand what a particle system is.
Now, a particle system is a technique in game physics that uses many minuit sprites or particles to simulate behaviors that are hard to produce with rendering techniques. Now, one thing to keep in mind is that a particle's system is generated through the graphics processing unit or GPU for short. Now, what exactly is a particle? Well, a particle is the smallest unit of any thing or something.
You can think of a particle as a single piece of snow or raindrop or even a fire flicker. When you produce many of these particles, you produce some effect. And that effect is essentially known as a particle system. Now, why exactly would you want to use a particle system? Well, for one thing, it increases performance. Along with that, you do have the ability to create unique behaviors that would be hard to recreate with regular animation.
Now, how easy is it to use a particle system in Godot game engine? Well, you can create a particle system through the editor, basically without code. On top of that, you are able to use code in order to create your particle system as well, if that's the route you want to take. In this episode, we will be taking a look at methods and properties and in the next episode we will be taking a look at examples. So this topic is split into two episodes.
Now, Godot gives you two different classes. The first class is called Particle's 2D and that is a node class that will emit your particles. You use the particles to denote class in order to create effects and your particle system. The next class that Godot offers you is the particles material resource class, the particles material resource class contains your particle properties and behaviors that the particles to denote class will use.
Basically a particle to denote can't run without the particles material resource class since your particle system will be based on the properties of the particles material class. Let's go ahead and take a look at that first. The particles material class inherits from the material class, which then inherits from the resource class. The first important property that your particles material resource class has is called the emission shape.
And this is a data type of emission sheet. And it basically determines the region where particles will start out by default. This value is set to zero. Basically, everything will start on a single point. The emission shape property has several different options. The first option, which is the default option, is the point or single point. Basically, all particles will be emitted from a single point. You also have the Spearin box. You can also choose different points and so forth.
It's best just to keep this value at its default, meaning value zero. Next on the list, we have the direction property and the gravity property. The direction property specifies the particles emission Direxion. By default, the direction is set to emit towards the positive x axis. The next property is called gravity. The gravity property applies its gravity values onto the particles. By default, the y axis is set to ninety eight.
What that means is basically a downward movement is applied to your particles. The next property is the spread property. By default, its float to value is set to forty five and the spread property describes the range of directions in which particles are created at. Basically it represents a range in degrees. For example, if you set it at forty five degrees, particles will appear in a range from negative forty five degrees to positive forty five degrees.
On top of that, you do have values that affect its velocity and acceleration. For starters, you have the initial velocity property and this property is the starting velocity that. Particles start moving by default. This is set to zero, and so in a sense, your particles will not move. However, because gravity will be applied to your particles, your particles will start basically falling downward. The next property is called the linear acceleration property. And the linear acceleration property applies an acceleration to each particle in their given direction.
Next, you have the angular velocity property and this is the initial velocity of the particles rotation. And of course you have the radio acceleration property and this is basically the acceleration of particles rotation. Both of these values are set to zero. The next property is called the damping property, and this is the rate at which particles lose velocity by default. This value is set to zero. On top of that, you have a property called scale. By default, it's up to one which means no scale is applied to your particles.
And this value is basically the initial scale of each individual particle. Next, you have the angle property and this is the initial angle rotation that each individual particle starts at. And on top of that, you can also set the randomness of the angles through the angle random property, which by default is set to zero. And again, the angle random property sets the rotation randomness ratio. The next property is the color property and this is the starting color for your particles.
And on top of that, you have a property cohu variation and this property sets the initial WHU variation apply to each particle. You use the Houtte variation property when you want to apply different colors in the lifetime of each individual property. Now some properties will need to use a curved texture resource class to set its value. For example, the scale curve and the huge variation curve. Basically, any property and the particles material class that has curve appended at the end of the property will most likely need to use a curved texture.
Now the curve texture is a resource class. The curve texture inherits from texture, which ultimately inherits from resource. Now a curved texture is a texture that shows a curve. The most important property in the curved texture class is the curve property, and it is of data type curve. Now the data type curve is what renders your curve. Now the curve data type is a resource class, so the curve resource class inherits from resource and basically the curve resource class is a curve that can be saved and reused for other objects.
Keep in mind that by default, your curve resource class has no points and this is what it would look like if there was a visual representation. When you create a new curve resource class, you basically create this graph. The x axis is a range from values zero through one. The Y axis is a range of values from zero through one and through points. You can create your curve now again by default. The Curve resource class doesn't come with any points. When newly created, you have to add your own points.
And so to add a point onto your graph, you use the add point method provided to you by the curve resource class. The most important argument is the first argument, which takes any vector to data type, which represents the position you'd like your point to be on the graph. Now that's basically it for the rabbit hole. That is the particles material class. Now let's take a look at the particles to declasse. Now the particles to denote class is your 2D particle emitter.
You use this note when you want to create a variety of effects and it inherits from the No 2D class, which ultimately inherits from the node class, which means you do have lifecycle scripts. Now, the particles Tuti class has two important properties if you'd like to show effects on the screen. The first property is called process material, which is a data type of material, and you use that material to process your particles. The next property is called texture and it takes any textured data type, which is just basically an image.
Now by default, if no textures are provided in the texture property, then squares are used. Now again, these two properties are important. If you want your particle system to do something on top of those properties, we have other properties that control our particle system. So let's go ahead and take a look at those. The first properties called Lifetime and it's set to the float value one. And basically the lifetime property is the amount of time a particle will exist in seconds. So by default, the lifetime of each individual particle is one second.
And when one particle dies, a new one is automatically created for you, the next property is called amount and the amount property is how many particles are emitted in one emission cycle. And each emission cycle is based on the lifetime value. So in this case, eight particles by default are created over the lifetime of one second. On top of that, you have the emitting property, which is set to true by default. And if true particles will be emitted, you need the emitting properties set to true.
If you'd like your particle system to show to the player on top of that, you have another property called Speed Scale, and this is just the speed scaling ratio of value between zero and one. Keep in mind that if you want to pause your particle system, you can set the speed scale value to zero. Next, you have properties that sort of give you an explosion effect, the first one being the one shot property. If set to true, only one emission cycle occurs. The next property is called explosiveness.
This property determines how rapidly your particles are created. In each cycle, this value can be set between zero and one. The best way to think about this is that lifetime multiplied by the explosiveness value is equal to the gap in time you'll see in the editor or when the game is running before the next set of explosiveness has occurred. So basically any value greater than zero will create this gap in time between each particle emission.
The next property is called pre-process. Now the pre-process property is very important because the value determines how many seconds of particle simulations have been calculated before the particle system is emitting to the scene. And the reason this is an important property to understand is because if you have multiple particle systems in your scene, you may experience some lag. And to alleviate this lag, you need to do some preprocessing before your game starts running.
And this is something that has to be done on your end. The last property to understand is the randomness property and this is the emission lifetime randomness ratio. So basically, if you set a value in the lifetime property, the randomness property can determine how many particles will live in between the values of zero and one if you leave the lifetime property to its default value one. Now the particles to declasse comes with two methods. The first is the restart method.
And when you call this method, it restarts all the existing particles. The next method is called capture rectangle and it returns a data type of rectangle to and basically it returns a rectangle containing the positions of all existing particles. This is useful if you'd like to use your particles with some sort of collision calculation. Now, it's OK if a lot of this went over your head. Hopefully you took notes because in the next episode we will be taking a look at examples of creating particle systems through the editor and through code.
Well, that's all I have for you in this episode. Thank you so much for joining me. Thank you for clicking the like button. And thank you for clicking the subscribe button. If you have any questions or comments, please feel free to leave them in the comments section down below. And I look forward to seeing you in the next episode. Have an amazing day.