TIL: Learn to Code in C++ by Developing Your First Game (Section 4, Lectures 125-129)

Disappointing. I had ambitious plans for ripping through these tutorials this weekend. Had a babysitter hired to come in and take care of Allegro Junior for a good portion of the weekend seeing as it was glorious Canada Day. (Un)fortunately she reported in sick and so it was a weekend that mostly consisted of hanging out with the kiddo. Disappointing not to have had the 12 hours of study time I was expecting… but hey, the kid seemed to have a great weekend so all is good in the grand scheme of things.

Section: 4 – Battle Tank – A Fun Tank Battle with Mortars

Lecture 125: Get the Player Controller with C++
Lecture 126: Add Tick() to PlayerController
Lecture 127: Creating an Out Parameter Method
Lecture 128: Finding Screen Pixel Coordinates
Lecture 129: Using DeprojectScreenToWorld

Lecture 125: Get the Player Controller with C++

-a world has one or more actors, an actor could be anything, it is likely that one of them will be a player controller (some games could have more than one player)
-the world specifies the game mode, the game mode specifies a player controller class, the player controller class instantiates the player controller
-we’ll add functionality here to get the player controller in the tankaicpp
-typing accurately is pretty damned important! In this particular case, I had two bugs -> I had forgotten to add () after typing GetWorld(). And I had typed ATank * ATankAIC[etc] rather than ATank* ATankAIC[etc]
-in the video Ben neglected to add a !
-apparently the API is different in UE4.16:

be sure to add
#include "Engine/World.h"

To quote Daniel from the Q&A from Lecture 77,

“…Unreal has changed how projects are setup now in 4.16 as it’s no longer including “Engine.h” in the project header. Whilst it should decrease compile times it means you would need to include any header you are using.

Lecture 126: Add Tick() to PlayerController

– right now, our player controllers don’t have a tick method, we’ll add it so that we can update the aim each frame
virtual void Tick( float DeltaTime ) override; can be added to the header, whilst we can add…
void ATankPlayerController::Tick( float DeltaTime) {
Super::Tick( DeltaTime );
// AimTowardsCrosshair();
UE_LOG(LogTemp, Warning, TEXT("Player controller is ticking"));

…to the .cpp
– Less confusing to have OnBeginPlay before Tick

Lecture 127: Creating an Out Parameter Method

– Our goal is to have a tank which will be possessed by either an AI or a player.
– Tank will delegate to an aiming component (not made yet)
– aside from that… this is really just about creating an output parameter (FVector type) and at this point doesn’t do anything other than return our hard-coded result of 1,1,1

Lecture 128: Finding Screen Pixel Coordinates

– Instead of a hard coded result, we’ll figure out where the cursor starts in screen space (pixels, not 0-1) — this is semi-hard coded.. not ideal since this means that we’re setting our UI manually in two locations. This can introduce bugs if we edit one later, and not the other.
– Important piece is that the member variables will be EditAnywhere so that we can adjust in BP

Lecture 129: Using DeprojectScreenToWorld

– Working out the direction in world location that the tank is aiming using APlayerController::DeprojectScreenPositionToWorld using the ScreenX and Y that we calculated in Lecture 128
– Holy freaking hell… using the high contrast mode makes coding in Visual Studio a nightmare. There’s no color coding at all… just red underlines making everything feel like a typo. I might go insane if I don’t upgrade my project to a newer build of UE…
– The code is refactored in this video. Watch out for returns, brackets, and typos!