‫Hello and welcome.
‫In this lecture, we're going to be architecting our gun such that when we hit the mouse button or the
‫trigger, then we are going to get a log message.
‫And this log message is the first step in getting many other things running off the back of this gun
‫architecture.
‫Let's dive in and see how it's done.
‫So we want this gun ultimately to be able to shoot and that is the core of it.
‫Why are we choosing to have the gun as the core of our shooting architecture?
‫Well, as I've already alluded to a little bit, we want to be able to support different types of methods
‫of shooting.
‫Now, what are the kinds of methods of shooting that we can typically have?
‫There is direct fire, which often uses ray tracing and direct line of sight to ascertain whether or
‫not a victim has been hit.
‫So it would go and say, okay, I can see that enemy.
‫It's that line of sight from the gun to the enemy is clear.
‫It hits him, so we have to do him damage.
‫Otherwise, if I missed and I didn't hit the enemy, it doesn't do damage.
‫That's one very easy way.
‫It doesn't really replicate the physics of a bullet, but there's no need to.
‫So for performance reasons we don't now with a rocket launcher or something like that, it's often a
‫very slow projectile.
‫We want to see the effect of that projectile moving through the air and the time delay can be important,
‫in which case we might spawn that projectile and see whether the projectile hits in 5 seconds time,
‫or we might go down a different route with bullet drop and rifles and sniper rifles over long distances.
‫So all of this could change depending on the implementation of our gun.
‫Now we're going to implement one gun during this section.
‫It's going to be a rifle, a direct shooting type of gun.
‫But in order to leave that architecture open for you to extend, we are going to make the gun responsible
‫for doing shooting.
‫So that means we have to go ahead and introduce some shooting architecture into our gun.
‫So we've got a gun.
‫H We want to create a public function to this that is going to allow us to essentially pull the trigger
‫on the gun from the shooter character or from wherever we're binding input.
‫In the case of the enemy, for example, we're going to be pulling that trigger from the eye.
‫So let's go ahead and create a void.
‫It doesn't have to have a return type pull trigger method and it doesn't need to take anything.
‫All we need to know is that we want to pull the trigger in this frame.
‫So having that is sufficient now I'm going to go ahead and create the implementation with control shift
‫P and create implementation.
‫And then in here, all I'm going to do is I'm going to put a YUI log and I'm just going to make it warning
‫to stand out and change the message to You've been shot like that and that's great.
‫So that's what we're going to call in our character DHCP.
‫So this is going to be a challenge to you.
‫It is some more input binding.
‫We've done lots of input binding here.
‫You've got lots of examples of input binding.
‫Go ahead and do this.
‫To hook up a shoot action, you're going to have to create a new action in the project settings for
‫shooting.
‫Bind that to your key, your right trigger, whatever you want to bind it to, then bind it in the character
‫set up player input component method to do this.
‫And then after binding the character, you should be able to call the pull trigger from within the function
‫that you have created on the character.
‫Remember to put a function in to character in order to set up the binding, rather than trying to bind
‫directly to that gun.
‫Binding directly to the gun isn't going to work.
‫You need to put a little function intermediary in there.
‫So pause the video and I'll give you a little bit of a hint or a little bit of a start if you're struggling
‫with that last part of the challenge of creating the intermediary function.
‫So here comes the hint if you don't want the hint, pause now.
‫But the hint is going to be we're going to do something like this, which is to have a new private function
‫called void, shoot and create the implementation over in C++.
‫And it's going to be in here that we call to the gun's own method.
‫So the gun's pull trigger, we're going to do gun.
‫And then call pull trigger on that from within shoot.
‫And this is what you need to bind.
‫Okay, so pause video again, if that's where you want to take things and then let's go and set up the
‫actions.
‫Okay.
‫So we're going to go over to our project settings.
‫So settings, project settings and we want to dock this and go to our input and we want to add a new
‫action and we're going to call it shoot.
‫And then we're going to bind this to the left mouse button and the right trigger, not the right trigger
‫axis.
‫The right.
‫Just trigger.
‫I thought that's what I'd selected, but I had not.
‫Okay, so we're binding to both controller and mouse and then we're going to go over and bind the axis
‫in our shooter character.
‫CP So copy this bind axis for jump.
‫I mean action.
‫Of course, I'm always going to get those two mixed up.
‫We all call switch over to the shoot axis here.
‫The pressed is what we want and instead of binding to jump, we're going to bind to a character shoot
‫instead.
‫Like so and let's go ahead and build.
‫It looks like that has succeeded.
‫Let's close that on down and see if it works.
‫So let's exit the game and hit play again and have a look at our output log.
‫Crucially, it play.
‫Yeah.
‫So if I hit the mouse button, it is working.
‫Let's see if the same thing happens if I use my right trigger.
‫Yep.
‫Right trigger is working too for firing.
‫So obviously a log message is not the best way of letting your player know that something is going on
‫in the game.
‫So in the next lecture, we're going to look at adding in particle effects to do just that.
‫I'll see you there.