Welcome back everyone in this video Our goal is to add script necessary to give our First Person character, a speed boost if they shoot a speed boost target. Now remember, we're going to have to quote unquote special targets in our level here, one that is going to give our character a speed boost. If we shoot that target and another one that's going to give us a time bonus, we're not going to be doing the time bonus target for now because we kind of need to lay some more groundwork down to get that working properly but this one we can address now. And this is going to involve a couple of different blueprints and the first one we need to work within is our First Person Character Blueprint. So find your content first person BP Blueprints folder and double click on your first person character here. And straightaway, I want to add a new variables.
So click on this plus variable button. Speed Boost additive is what I'm going to choose to name this variable. And I want this to be of the float type. And I want to add a default value down here. So go ahead and compile and I'm going to change this to be 600. Now it's worth mentioning when we talked about player metrics, we selected this character movement component that comes by default on a first person character.
And within here, there is a parameter called max walk speed. This is what determines how fast our character goes. And basically what I'm aiming to do is I want to add on to this max walk speed. I'm essentially going to double it with this speed boost additive when we shoot that speed boost target. Okay, so with this variable created, come to your Event Graph and find some empty space. Again, there's some existing scripts in here.
I'm just going to right click, and I'm going to add something called a custom event and just do a search for custom. And you will see that option to add a custom event. And I am going to call this speed boost. Now a custom event is one that you create. And the way that this gets called is you need to call it from either this blueprint or in other blueprint, and we'll take care of that in just a moment. So with this event created, we're going to build some scripts off of it.
First thing we want to do is bring in a reference to our character movement component, like so can just drag and drop that into your graph. And out of this, I need to drag out a wire, and we want to get max walk speed. And again, that was that max walk speed parameter I just showed you. And also while we're here, I'm just going to drag out another wire from our character movement component and type in set max walk speed. gonna drag this into position like this. Okay, next thing I'm going to do is drag any reference to our speed boost additive.
So just left click in drag this in and say we want to get this and then off of this, I'm going to drag out a wire and type in the plus symbol and I'm going to be searching for float plus float. And what I want to do is plug in our max walk speed into this so that we can add our characters current map x walk speed, which is 600. As you can see right here, I have that selected, our max walk speed by default is 600. And I want to add our speed boost additive to it, which is also 600. And then I want to take the result of this and plug it as our new max walk speed. So we're essentially taking one adding it to the other and updating our characters, Max walk speed.
So let's hook this in like that. And I'll actually double click on this blue wire to bring in a little reroute node just for organizational purposes. And actually, what I'm going to do next is bring in a node called a retrigger bubble delay and I'm going to set this to be five seconds And then I am going to drag another wire out of our character movement. Actually, what we need is a copy of our set max walk speed. So let's actually just select that Ctrl C to copy it Ctrl V to paste. And we'll hook it in like this.
And our target here is actually going to be our character movement component. And I can drag a wire off of this point right here to extend from our character movement component. And I'm gonna set this back to be 600. Why 600 because if you remember right, our characters, movement component, default max walk speed is 600. So essentially, what I'm doing here is I'm saying whenever this speed boost event gets called, which is not currently, I want to take our characters current max walk speed, which is 600, and add 600 to it to make it be 1200. And then with this retrievable retrigger a bowl delay of saying after five seconds, set it back to its default 600.
Now you've seen me place delay nodes, and this is a retrigger oval delay, what's the difference? Well, we could have more than one of these speed boost targets out in our level. So as soon as we shoot a speed boost target, we're going to call this custom event to happen to trigger at which point this five second delay is going to start ticking down. Think of this as a five second timer. Now, let's say this timer goes down to one second, and we shoot another speed boost target. What that is then going to do is it's going to reset this back to five seconds with a delay No, that would not happen.
The retrigger will delay. If you happen to retrigger this event again, it'll set this delay back to its default, in this case of five seconds. seconds. So again, we shoot a target, we start our speed boost for five seconds and this is going to slowly take down. And if we shoot in other speed boost targets before this time expires, it's going to reset our timer back to five seconds here. Alright, so with that done, let's just drag out a marquee selection, left click and drag, tap that C key.
And we'll call this speed boost. And you know what, for the time being, let's output this value, our max walk speed here, too to our viewport window, so I'm just going to drag a wire out of here and do a print string and plug the output of our max walk speed here into our in string here so that we can output that value to our gameplay window. I'm just going to compile in save Here. And next, we need to take care of the other end of this, which is calling this custom events when we actually shoot a speed boost target. So with that, we're going to jump back to our level editor come under your blueprints actors folder in your first person project. And let's double click on our BP target plus speed target.
Now, this is going to be some functionality that is specific to this targets. We don't want to put this in the parent target, because this is going to be functionality that is shared amongst all targets things such as destroying the target, but this is going to be specific to the speed boost targets. So double click on this guy. And again, if you see this view right here, you can just click right here to open up the full Blueprint Editor. And what do we want to do? Well, we want to do something if we overlap this target collision, right?
Here with a first person projectile so go ahead and right click on this add event on component begin overlap. And the thing we want to check that is overlapping it is a first person projectile so out of this other actor, type in cast to first person projectile and the first thing we want to do is drag out of this as first person projectile and we will destroy the actor. Now, this should all be happening anyways, but it's still fine to add it here in our speed boost target. And then what we are going to do is we are going to right click and we are going to get player character and I'll explain why. Just a moment because off of our destroy actor, I'm going to drag a wire off in do a cast to first person character. Now, up until this point, we have only really used this cast to first person character off of this, like on component begin overlap type node, in which case we could always just kind of plug in the other actor.
Well, here we are casting to our First Person character, meaning we want to talk to our First Person character. But we need to plug in an object. It wants to know what kind of object Are you talking to, in this case, we want to talk to our player character. So that's what this is for right clicking getting our player character, we can plug this into our object so we fulfill that requirement. Okay, once we are able to cast to our First Person character, we can then Call upon all the functionality and variables that are contained within this first person character, which is what we want to do now just remember in our First Person character, and I'm just going to jump over blueprints here we created a custom event called speed boosts, but nothing is calling for this event to trigger. Jumping back over to our target blueprint, our target speed up blueprint.
Here we can drag a wire out of our casting to the first person and simply type in speed boost and you can already see it says call function speed boost. So this is actually going to call this is a function that is going to call for this event, this custom event to fire off. Okay, that's very key right there. And then lastly, let's drag a wire off of this and I want Do a place sound 2d. And I do have a sound effect here in mind that I want to play and it's going to be V r underscore Open. Open Q, this is just kind of a special sound effect to let us know that something kind of special happened.
And I do want to actually expand and bring on some more advanced properties for this node that can do that by clicking this little down arrow. And I actually want to amp up the volume here by a factor of two. And then I can left click and drag out a marquee selection around this bit of script, tap that C key and I will call this boost speed. If shot by pro jek tile answer let me just zoom in, zoom in on this a little bit. So if you want to pause the video and see what this script is You can grab that. Remember this speed boost node, you're only going to find if you drag out of the s first person character pin right here that is a context sensitive find right there.
So then I'm going to Compile and Save. And moment of truth here. We want to play this but firstly, we need to actually bring in a speed boost targets. So let's bring one of these guys in. I'm just going to rotate it around a little bit like so. I will check his standalone target because currently that is our only way to spawn in these targets.
And then I want to grab the trigger volume here in our components. And you can see I've got it highlighted and I'm just going to move this down and just expand it out a little bit to make this easy for My character to overlap, set it kind of back here, sort of back where my other trigger volume is, doesn't have to be too perfect. And then I'm going to jump in and play and watch my speed movement and also look in the upper left hand corner of my window, when I do get the speed boost, because remember, I'm using a print string node to actually output my max walk speed. So here we go. pipe, tap, net F key open, tapping that F key to open. Alright, speed, now watch.
I am actually zoom, zoom, zoom in right along. Keep looking at the upper left, and you see that number 600. Returning when I get back to normal speed, now I've got a little bit of an error right here. So let's check this out. And this error right here is not at all surprising because this has to do with some of the things that I was talking about. In the parent blueprint when I was talking about possible error messages that could appear.
What this is saying is that it wants to kill off our First Person projectile, but it's already being killed off in our target parent. So let me just bring on our target parent one more time and I'll explain what's going on here. Okay, so where we are destroying our projectile. We are saying when we shoot a target, we are casting to our First Person projectile and then we're destroying the first person projectile, right? Because this speed target is a child of this. This should already be happening when we destroy the target.
So if I jump back over to our BP target speed, I don't actually need to run this at all. This destroying of the first person project First Person project all because we're already doing that in the parent. So if I was to simply eliminate this right here and simply keep this hooked in like so. Now if I Compile and Save, I should be able to jump in and play, shoot that target all over again and I should not get that error message. So let's go ahead and try that. I have to open F to open it I'm going faster.
And you can see my speed is now set back to 600. And let's exit out and now no more warnings. So that is an example of the types of warnings that you may be getting if you're not being careful. So I'm glad that example came up. One more time here is the scripts on our target speed boost. And once again, On our first person character and actually we don't need this print string anymore, so I can go ahead and get rid of that that was just to output our max walk speed.
Turning back to 600. So there you have it. I'm gonna Compile and Save one more time and each of these blueprints, Compile and Save. That is going to do it all for this one guys. We will see you in the next one.