‫So we're going to create a fire function and we're going to associate this function with our left mouse
‫button.
‫And here you can see that I'm drawing debug spheres at the tip of our turret barrel just to prove that
‫this action mapping is working.
‫Whenever I click the left mouse button, something is happening.
‫Hey, welcome back.
‫In this video, we're going to talk about creating a fire function or a function we can use for when
‫we want to spawn our projectiles.
‫So we're going to create a fire function and we're going to bind it to an action mapping.
‫Now, we've been using axis mappings.
‫An action mapping is similar.
‫Let's talk about it now.
‫Here's a section of a screenshot of the fire action mapping that we have in our project settings.
‫You'll see that we have the left mouse button assigned to the fire action mapping.
‫Now an action mapping is very much like an axis mapping.
‫You can assign a key or a button to it.
‫And just like an axis mapping, it requires a function that can be bound to the action mapping.
‫Now, axis mappings fire off every single frame of the game.
‫They're like the tic function and the float value passed in changes depending on which buttons are being
‫pressed.
‫Action mappings are slightly different.
‫A callback function bound to an action mapping takes no input parameters, and all that happens is when
‫you press the button, the function gets called.
‫What goes on inside of the function is up to us as the developer.
‫Now, action mappings are one offs.
‫They don't happen every frame.
‫They only happen once when you press the button.
‫So if you release the button and press it again, the function will be called once more.
‫Now, when we bound functions to the axis mappings, we used bind axis for action mappings we use a
‫function called bind action and it takes inputs similar to bind axis.
‫It takes the name of the action mapping as a string literal.
‫It also requires a pointer to the class.
‫We're binding the function on for which we can use this, and it takes, of course, a callback function.
‫Now an additional parameter it takes that bind axis does not require as an enum constant specifying
‫whether or not we'd like this function to be called when we press the button or when we release the
‫button.
‫So there are two options for this input parameter the enum constant, i.e. pressed and the enum constant,
‫i.e. released.
‫This means we can call bind action passing in i.e. pressed if we'd like to bind a callback function
‫for when we press the button and instead if we used i.e. released then our callback function would be
‫called when the button was released for our fire function.
‫We're concerned with when we press the button.
‫So let's make a fire function and bind it to the fire action mapping.
‫Now I'm here in base spawn and the reason I'm here in base pond is because this fire function is something
‫that we can use in the tank class and in the tower class.
‫So if we place it here in base pond, then both Tank and tower will inherit this function.
‫And since both the tank and the tower are going to fire projectiles, then they can simply inherit the
‫function and use it.
‫Now, since I'd like access to the function in both the child classes, I can place this function here
‫in the protected section, just like rotate turret.
‫So under rotate turret I'm going to create a void function called fire that takes no inputs and we can
‫go ahead and define the fire function in based upon CPP.
‫So here's based upon CPP and just under rotate turret, I'm going to place the fire function and we
‫need to fully qualify this function name and give it a function body.
‫So now we have a fire function.
‫Now the next step is to bind this to an action mapping.
‫Now we only want to bind this function in the tank class because the tank is the only class that will
‫be taking user input.
‫We'll be calling the fire function in the tower class later, but that will be as a result of code we
‫create and not as a result of user input.
‫So we're here in Tank CP and we're going to bind this and set up player input component just like we
‫used bind axis.
‫So we're going to use the player input component.
‫So player input component and the function is going to be bind action.
‫Now the first input is going to be the string literal, which we're going to wrap in a text macro as
‫usual.
‫And this action mapping is called fire.
‫Now the next parameter is going to be that enum constant that determines whether or not we'd like this
‫function to be called when we press the button versus when we release the button.
‫And we're going to use, I underscore pressed.
‫Since we'd like our function called when we press the button.
‫Now, next is the user class object that's going to be this.
‫And finally we have our callback function so we can say a tank fire.
‫And now our fire function is bound to the fire action mapping.
‫So we know that our fire function is bound to the fire action mapping, but we'd like some visual confirmation
‫and that's what your challenge is going to be.
‫So in the fire function, I'd like you to draw a debug sphere.
‫We've already seen how to do this, so go ahead and fill in the parameters with values that you think
‫are appropriate.
‫Use the location of the projectile spawn point.
‫Now the projectile spawn point is a use scene component and you've seen components have a function called
‫get component location.
‫This returns an F vector.
‫This is what you can use to get the projectile spawn point location.
‫Now when you call draw debug sphere, use a duration of about 3 seconds so we can see that sphere for
‫a little while before it disappears.
‫Pause the video and do this now.
‫Okay.
‫So I'm back here in Bass Pond and here in Bass Pond.
‫CP I'm going to include draw debug helpers.
‫So we have access to draw debug sphere.
‫So I'm going to say include draw debug helpers.
‫And now down here in the fire function, we can draw the debug sphere.
‫Now, the first thing I want to do though is get the location of the projectile spawn point.
‫Now I can create a local f vector for this and I can call this projectile spawn point location and I
‫can initialize it using the projectile spawn point.
‫And calling get component location.
‫So now I have the location of the projectile spawn point and this is what I can use when calling draw
‫debug sphere.
‫So I'm going to call draw debug sphere.
‫And for the first input we need the world and we know that we can get the world using get world next.
‫We need the center of the sphere that's going to be our projectile spawn point location.
‫So that will be what I pass in as the second parameter.
‫And next we need the radius of the sphere.
‫Now I'm going to have a small sphere.
‫I'll give it a radius of say 25 F for the number of segments I'm just going to use 12 and for the color
‫I can use F color.
‫Read Now four draw persistent lines.
‫We're going to have our lines hang around for 3 seconds so we can make this false because we don't want
‫them to persist forever.
‫We're going to give this debug sphere a lifetime of three F So let's go ahead and compile this now and
‫I'm going to hit play and click and now we can see our debug sphere and of course it goes away after
‫3 seconds.
‫Now this is good confirmation that our action mapping is working and it's also giving us verification
‫of the location of the projectile spawn point.
‫So once we actually start spawning projectiles, we know that they will spawn at the correct location
‫as indicated by the debug sphere.
‫So this is great.
‫So in this video we created a fire function and we bound it to the fire action mapping.
‫And to prove that it was working, we drew a debug sphere at the projectile spawn point whenever we
‫click the left mouse button so we have a fire function, we're almost ready to start spawning projectiles.
‫And we've also placed this function in the base pong class.
‫So that way our tower can also use it.
‫So in the next video, we're going to discuss how our tower is going to use this function.
‫I'll see you soon.