‫Hello and welcome this lecture.
‫We're going to be using those functionality nodes to manipulate the objects in our scene on request.
‫So if I hit a spacebar, I can make this cube bunny hop up and down.
‫Let's dive in and see how this works.
‫So it's all very well being able to get data out of objects in the scene.
‫But what about making them do stuff?
‫Well, what I would like to do is use our physics system here to add a force to an cube and make it
‫jump up in the air or be the first thing that we do with our programming that actually allows it to
‫act in response to something.
‫Now, the way I want to do this is so that it does it in response to actually pressing a key.
‫We've used this Begin Play event in the past.
‫I want to introduce you to some new events here.
‫What we're going to do is we're going to right click in the level blueprint and we're going to search
‫for Space Bar.
‫And you can see that gives us a keyboard event under the category keyboard event space bar.
‫We can click on that and we're going to bring in a new event node that's this red one that tells us
‫when something should happen.
‫And you can see it has two execution pins, one for when the space bar is pressed and one for when the
‫space bar is released.
‫So let's use this, shall we, to actually print the mass of our cube so I can do this by selecting
‫all these nodes, and I can shift click to select more.
‫I can drag them down into place and I can drag from the pressed execution pin to the input pin of our
‫print string node.
‫And you can see that that's going to actually have two execution pins go into print string, which means
‫that this can be executed either when the spacebar is pressed or when we begin play.
‫So let's go ahead and hit play and see that actually works.
‫So we've got the thousand that comes up when we begin play space bar and thousand comes up again.
‫What I want to do is for this to actually apply a force upwards.
‫Now in actual fact, we don't want it to apply a force, but we want to have it apply something called
‫an impulse.
‫Now, the difference between the two, in physics parlance, is that a force happens over a certain
‫amount of time, whereas an impulse is instantaneous.
‫So what we're going to do is we're going to delete our print string node and we're going to delete the
‫get mass and the conversion node as well.
‫But we're going to leave the cube and static mesh nodes.
‫So we've got our static mesh reference.
‫So if we pull off of this, we're going to look for something that can add an impulse to our cube.
‫Now notice that when I'm doing this, the search menu here has got context sensitive switched on.
‫And that's quite important because this means it filters down the nodes available to the ones that use
‫the static mesh component object.
‫So if I look for impulse in here and type in impulse, you can see there is an add impulse node here.
‫There's a few of them, but there's an ad impulse one.
‫Let's go ahead and get that.
‫You can see it's got execution pins that tell us when we should add the impulse so we can go ahead and
‫instantly connect this up to the space bar pressed execution node.
‫So this should mean that the impulse will get added when the space bar is pressed.
‫So we're doing this we're adding this impulse to the static mesh component, but there are other properties
‫here on the node that we need to fill out, particularly the value of the impulse itself.
‫Now this has three parts to it an X, Y and a Z.
‫In fact, when we have these three parts, it's said to be a vector, but we'll get on to vectors in
‫much more detail in a later lecture.
‫Notice this X, Y and z actually corresponds to the x, y and z we get on our movement widget, on our
‫cube, and also in the bottom left hand corner of our viewport.
‫You can see there's an X, Y and Z.
‫They're showing us which directions these values basically relate to.
‫So what we can do is we can add in a value.
‫If I wanted it to go up, I would use the Z direction and we can put in a value into here, such as,
‫I don't know, 100,000 like this.
‫Let's try that out.
‫We'll go and hit play and hit our spacebar.
‫Then at the moment nothing is happening.
‫And the reason for that is that the value I've entered here is too small.
‫So I'd like you to take the challenge to tweak the impulse to a value that actually jumps it up into
‫the air.
‫So try multiplying the mass by 100.
‫You may find that that is in the right ballpark and at least gets the cube to move, then play around.
‫With this value to get something that you like the look of and that acts in a way that's enjoyable to
‫you.
‫And what if you had added it to X and Y instead?
‫What different effects do you get there?
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫So we're going to try this out.
‫I'm saying 1000 and I can actually do the multiplication right from within here using asterisk multiplied
‫by 100 should give us the rough ballpark we play and hit our spacebar.
‫You can see it's doing tiny little bunny hops.
‫Not a great deal.
‫And if I hit spacebar repeatedly, it starts to go a little bit higher in the air.
‫So I'm actually going to multiply this whole value again by asterisk four.
‫So four times the value hit play and then make it jump in the air.
‫And that's a little bit more of a decent bunny hop that we're getting there now.
‫The reason we had to multiply by the mass is because of this formula.
‫That force is actually equal to a mass times and acceleration.
‫So if we want a certain acceleration, we need to multiply it by the mass and that gives us the force
‫required.
‫There's also a similar equation for an impulse where actually if what you want is a change in velocity
‫rather than an acceleration, then you essentially multiply that by the mass.
‫So what I was saying is that I wanted to increase the velocity by 400, which in this case is four meters
‫per second because Unreal uses centimeters as its main unit, then 400 multiplied by the mass of the
‫cube, gives us the impulse required.
‫However, I don't actually have to do that maths if I don't want to.
‫If my desire is a change in velocity, then you see there's this little checkbox down at the bottom
‫of the node which is labelled Velocity Change or val change for short.
‫And if I check that it basically ignores the mass entirely and just applies whatever velocity I want
‫so I can just type in 400 directly into the Z and that will apply a velocity of 400 in the upwards direction,
‫400 centimeters per second.
‫So if I go ahead and play, you can see that the impact is exactly the same.
‫However, now, no matter what mass I set on the cube, it's still going to jump by the same amount.
‫And the final part of the puzzle here is what if I had put this on the X or the Y instead?
‫So if I cut it out of the Z and I put it into Z, Y and I maybe I cancel out Z to zero entirely, if
‫I hit play and hit the spacebar, then you can see it's shifting it over to the side, over to the left,
‫which is the Y direction.
‫If I'd done it in the X, it would shift it forward, which is the X direction.
‫So I'm just going to put that back so that it's just 400 in the Z direction.
‫We can hit play to make sure that that's the case and we've got our bunny hopping.
‫So in this lecture we've seen how we can use nodes to actually do something.
‫We've also looked at vectors and forces and impulses a little bit to understand the physics of those
‫systems.
‫I'll see you in the next lecture.