Hi, welcome to this new video. We're going to continue working on project 1, which is a particle system, and we're going to be adding forces. So let's talk a little bit about forces that we can apply to a particle, right? So it will happen that we might want to control a particle in some particular way, and we will do that by including certain forces, forces such as gravity, wind, turbulence, drag and so forth, right. So these forces are external influences that make the particles change, and they're mostly represented as form of vectors, right. So the vectors will, in some cases, might have a position, right. If you think of a fan, like it might have a position, but in other cases, it would be just something like gravity that is basically applying a force that is a downward force at all times, right. So, let's just evaluate how we would actually do the computation of forces. In order to do kind of a physics based computation of forces, we're going to use three variables, we've been using two so far, which is position and velocity. And this is a simple way of updating the position of a particle, but we're going to add acceleration. And acceleration, if you really go into what acceleration is, is the rate of change of velocity. So velocity is the rate of change of position, right. So think of the particle is at any time is moving with its velocity, but that velocity might change, right. It starts like, maybe like you start getting drag and that velocity starts getting slower, right. Or you get a gust of wind and you start, the velocity starts getting stronger, right. The way in which velocity changes is affected by the acceleration and the velocity, in turn, passes, updates the position, right. So how do we do that in code? Well, we will need a velocity, sorry, an acceleration variable that will also be a vector. A vector that we will refresh every frame, right. We're going to be recalculating that velocity vector every frame. But the velocity vector won't be refreshed every time, every turn, right. We're going to keep that velocity vector what it is, and either the acceleration will subtract or add to that velocity, right. The important thing is that we do this sequence of, we pass the acceleration, it's added to the velocity, the velocity is added to the position, right. And then we reset the acceleration. Those are the third, the first three lines of the update particle and then when we compute forces, we do any force over the acceleration, right. So we might encounter we're close to a proximity of, again, like a fan, and the particle might start flying in a particular direction, or we just basically add gravity to the acceleration, right. Or something like that. So let's see how that kind of plays out when we start adding this information to our code. Let's jump into our script. So I'm here back at our script where we left it from last video, if you haven't covered that video, start there. So this is the second video in the project 1 series. So let's see, we're going to be doing most of our work, I mean, just as a recap, where we should be. It's like we have an emitter, right, spreading particles from the center, right. And if we go into our particle tab, we will see that our update calculation at the moment is rather straightforward, it uses self position.addvelocity. So to the position we add the velocity. We need to do an extra step here, so we need to add a new vector, self.acceleration, so let's do ack. So this is going to be a new Pvector, 0,0, so it's going to be empty. So we're going to allow forces to interact with this vector. And now in the update, we're going to say, let's just add the acceleration to the velocity, right? So self.velocity.add self.acceleration, right? Right now the acceleration is zero, so there shouldn't be any difference, right. We should be able to run this and nothing should change, but we want to start changing this acceleration. The other thing that I want to do, as I mentioned before, we want to reset the acceleration at the end of every frame, every update, basically we calculate the new position, but then also we reset the acceleration. So the acceleration goes back to zero after the update function, right. So what we're going to do is include a new function and again, remember that we're kind of trying to be modular in terms of, how we write our code and so that we can maintain it. And often if we find mistakes, it will be just within one little chunk of it, compute_forces, self, right. Here, what we're going to do is add, so in the compute forces function, we're going to add one force to the acceleration, right? So let's create a force here, we could say g for gravity, right? Or we could even call it gravity. It would be a Pvector of 0,0.01, right. So I want to just give it a very small push, remember that this is something that is going to be affecting the velocity every frame, right? So we're going to put a very small number here, it's going to be our kind of synthetic gravity, right. Something that would represent a form of like a downward motion, we know in processing that the y-axis is down. So we're going to be assuming that the particles will have gravity falling down, but you could actually create an arbitrary gravity in any direction, right. So that's the gravity vector or yeah, the gravity vector going down and let's just add that self.acceleration.add gravity, right. So this is kind of, we're using these compute forces here, this is kind of a global force. Later, we're going to see how to create forces that it's a class and it can interact with our particles in different ways. But right now we're just creating kind of a general understanding of how forces would be computed into the system. So we have that, so we have compute forces. The last thing we need is actually to invoke this line of code. So our function computeforces self.com put forces here, we'll do it at the beginning. So before the update, it needs to be done before the update. If you remember any, the update will actually delete or make sure that the acceleration is zero here. So let's see what we get at this point. Let's see, so we have, you see the same particles now go out, but they actually fall and they actually fall based on this gravity. If you want this gravity to be stronger, you could see that the particles fall weaker, right. So that's kind of neat, we could actually start including, as I said, we could actually include that 0.502 in the x-axis. And you would see that you can create a force in this direction, right. And because we're starting the particles with a velocity that is random, right. Some of them will start in an upward direction, downwards, left and right, so you get this kind of explosion effect. But if you want to manipulate the initial velocity, you would go back to the this definition. How is the initial velocity being defined? If you don't want to see any difference in the particles, you might just put a zero there and the velocity to start with. And you will depend primarily on the acceleration provided by the force, that's something that you can also try. But at this point, we have a good setup, we know how to apply forces to our particles, so we can really start tinkering on how to create a system that is more expressive and more complex. So I'll see you in the next video.