‫Hey.
‫Welcome back.
‫We're ready to finish our game, which means there are just a few things left to do to polish up our
‫game and get it in a state that we are happy with.
‫So get ready to finish this game up.
‫We're almost done.
‫We're just going to add a couple of features.
‫I'd like to make the camera movement a little smoother, so we're going to start with that.
‫I've also noticed that the towers still fire projectiles after the tank has died, so we can make an
‫easy fix to the code to prevent that from happening.
‫And also, I'm going to visit a potential issue with the projectile spawn point.
‫So let's jump in and polish up this game.
‫Now, the first thing I'd like to look at is the camera movement.
‫So if I go ahead and hit play, I'll just show you what I mean.
‫As I move around, you'll see that the camera follows exactly with our movement as we turn and as we
‫move forward and backward, the camera just sort of automatically follows along.
‫Now, there's a nice trick we can add to this camera that can make it a little bit smoother.
‫Let's go ahead and open up BP pond tank.
‫Now here in BP Pond Tank, I'm going to select our spring arm component.
‫And if I search for camera lag, I'll see here in the lag section, there's this checkbox enable camera
‫lag.
‫I'm going to check that and enable camera rotation lag.
‫I'm going to check that as well.
‫Now, this allows us to have the camera lag behind and smoothly catch up, which creates a nice sort
‫of professional camera effect.
‫Let's go ahead and hit play and test this out.
‫So notice as I move, the camera takes a short amount of time to sort of catch up as we're moving.
‫And the same goes for when we're rotating.
‫So it's like there's a bit of inertia and the camera is on some sort of sliding track and it slows to
‫a stop.
‫Now we can select the spring arm and we can change the camera lag speed and rotation lag speed.
‫So, for example, if I place this at a smaller value, say five and five rather than ten, now let's
‫take a look at how it looks.
‫So I'm moving and you'll see that the camera has a bit more lag.
‫Now, we can increase or decrease this as we see fit.
‫This is something that you can experiment with and sort of find the values that work for you.
‫Here we have a value of two and for me that's a little bit too much lag.
‫So I think something between five and two would work for me.
‫If you like this sort of value, then maybe you'll keep it at two or maybe even lower.
‫But I'm going to put this at a value of, say, four for the camera lag speed and four for camera rotation
‫lag speed.
‫Let's take a look at how that looks.
‫So as I move, the camera lags.
‫There's clearly some camera lag, but it's not too much.
‫I think this actually looks pretty good, so I'm pretty satisfied with that.
‫Our next item is the tower firing after the tank has already died.
‫Let me just go ahead and show you what I mean.
‫There we go.
‫The tank has died and the towers are still firing.
‫Now, this is because the tank still exists.
‫And as long as it's in fire range, the towers will continue to fire.
‫This is easily handled by having a sort of variable that we can check to see if the tank has died.
‫So I'm going to go into the tank class here and tank, and I'm going to add a Boolean variable that
‫we can check to see if the tank is still alive.
‫And I'm going to make this public since we plan on accessing it from outside the class.
‫So I'm going to make this a bull variable called Be Alive, and I'm going to set it equal to true by
‫default.
‫So the tank will start off in the alive state and then as the tank dies, alive will be set to false.
‫And that can happen in tank CP in handle destruction.
‫So let's go to handle destruction here.
‫And after we've set these other properties, I'm going to set B alive equal to false.
‫So since we're setting B alive to false, we can know if the tank has died and then we can simply prevent
‫firing the projectiles by checking this boolean.
‫So let's go into Tower Dot, CP and here in check fire condition.
‫We can make sure that the tank is still alive before we fire.
‫So first I'm going to see if tank is valid.
‫I'm going to say if tank is equal to null pointer, then I'll simply return early.
‫That way we know Tank will be valid and then in our check to see if we're in fire range, I'm going
‫to add an and and see if Tank be alive.
‫If tank.
‫Is alive, then we can fire.
‫If Tank is not alive, we will not fire.
‫Now, you may be wondering whether or not it's a good idea to put the return on a single line like you've
‫seen me do in previous videos.
‫And this is a good opportunity to discuss Unreal Engines, best programming practices, and recommendations.
‫Unreal engine coding practices do recommend that you have curly braces with a body for all of your if
‫statements, even those that have a single statement.
‫And the reason is because if you plan on adding multiple lines of code to this, then you already have
‫the body here.
‫And it's also more clear.
‫And that also brings me to another point, which is my use of auto.
‫I used auto here in the projectile class a couple of times, and while this can be efficient, it's
‫not as obvious what the types are at first glance, which is why the use of auto is also not recommended
‫in unreal engine coding practices.
‫If you want to stick to Unreal Engine recommended coding practices, you can replace these instances
‫of auto with the actual type.
‫For example, here, get instigator controller returns an A controller so we can change that to a controller
‫and that's a pointer.
‫This you damage type static class returns a U class so we could use you class here and of course get
‫owner up here returns an a actor so we could use a actor instead of auto here and now if you look at
‫this code, it's a lot more obvious what these types are, whereas auto just sort of masks everything
‫and allows you to be lazy and get away with not typing the types.
‫Now sometimes I'm not sure what a big expression returns, so I'll use auto just to see what that type
‫is and then later I'll replace it with the actual type.
‫So that's another way you can use auto to help you learn the types return by long, complicated expressions
‫like this.
‫So since we're in the polishing up stages, I'm going to replace auto with the actual type names here
‫in projectile.
‫I'm also going to go into base pawn in the fire function where we have this projectile and this is returned
‫from this big long expression here.
‫Spawn actor is going to return an a projectile in this case so I can replace this with a projectile.
‫Okay.
‫So that's going to polish up the code on the C++ side.
‫Let's go ahead and compile this.
‫And with a successful compile, let's hop back into the editor and we're going to hit play and let's
‫just make sure that those towers stop shooting at us after we've died.
‫So there's one hit.
‫There's another one, and I'm waiting, and I don't see any more projectiles.
‫Perfect.
‫Okay.
‫So the last point I'd like to cover before we wrap this up is the projectile spawn point.
‫Now, let's select that here in BP Pond Tank and make sure that it's spaced far enough away from the
‫barrel.
‫Before we do that, I'm going to place it really, really close and show you some issues that could
‫potentially arise.
‫Now, as I'm moving forward and clicking the left mouse button, you'll see that I don't see the projectile.
‫In fact, I don't see it at all because it's just too close.
‫We're already getting a collision.
‫It's being destroyed before it can do anything.
‫So make sure that it's a good deal away from the barrel.
‫We're spawning some smoke anyway, so it's going to look like a smoke trail is following behind it.
‫So this will still look pretty realistic.
‫So that looks pretty good.
‫And while we're on projectile spawn points, it might be a good idea to go and look at the BP pond turret
‫and select its projectile spawn point.
‫And if you've had any issues spawning projectiles from the turret, you might want to make sure it's
‫a good distance away from the barrel of the turret as well.
‫So there we have it.
‫We have a functional game and it looks fantastic.
‫We have the ability to roll around in the world, we have the ability to shoot projectiles and they
‫blow stuff up.
‫If we hit a tower, we can destroy it.
‫If the tower hits us, it can destroy us.
‫Just like that.
‫And we have winning and losing conditions with HUD widgets that display on the screen and tell us whether
‫we've won or lost the game.
‫So this is fantastic.
‫And if you would like to package this game, you can easily do so by going up to the top and clicking
‫on the platforms icon either for Windows, if you're on a Windows machine or for iOS, if you're using
‫a mac machine, then of course you have these other options.
‫If you'd like to package for other platforms, I recommend you do some research online to look up the
‫different platforms and how to package for them.
‫I'm on a Windows Machine so I can simply click package project for Windows here and it's going to ask
‫me where I'd like to package my game.
‫Now I have my project here in Tune Tanks.
‫I'm going to right click, create a new folder and I'm simply going to call this build.
‫That's typically where you would put a packaged project.
‫So I'm going to select that folder and allow Unreal Engine to package up my game.
‫It's probably going to take a few minutes and once it's done, I should have a packaged game.
‫Okay.
‫So once I've finished packaging we should see build successful in the output log and then we can look
‫in the folder that we designated for our packaged project.
‫For me, it's going to be this build folder.
‫Now I packaged four windows, so I have a Windows folder and here is my tune tanks, dot xy.
‫It's an executable.
‫I can double click on it and here is my final project.
‫I can shoot.
‫I can dodge.
‫Looks like my enemy towers can shoot at me and I can destroy them.
‫Yes, I can destroy them.
‫They can destroy me, it looks like, and I can lose the game.
‫And of course, if I was a bit more skilled, I could win the game.
‫And for your final challenge, I'm going to task you with adding your own flavor to the game.
‫Make this game your own.
‫Find some new sounds or effects or meshes and create some funky looking towers and tanks.
‫Add more towers, maybe add different skill levels, make the towers harder and harder as you progress
‫throughout your level.
‫Maybe level up the tank, give it a level that you can increase as you destroy more and more towers.
‫Maybe you can add new level geometry and make the tank climb up ramps and try to destroy tanks in hard
‫to reach areas.
‫The possibilities are endless, but most importantly, have fun.
‫While you're developing your games.
‫You're not going to pause the video for this challenge.
‫This is going to be something that you can do from this point forward with your game projects.
‫So congratulations.
‫We finished our game.
‫I hope you enjoyed this section.
‫I had a ton of fun.
‫This is a great game project and you've come a long way.
‫You've learned a ton of skills throughout this section of the course, so I hope you're ready to move
‫on to more exciting things.
‫Thank you very much.
‫I'm Steven and I'll see you soon.