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

Unreal Course Learn to Code C++ by Developing Your First Game lecture 109

It’s time for the Holidays! I’m off work for a bit while I deal with… you know… the winter holidays and all that that entails. I’m also going to be moving to Montréal in about a week [!!?] so basically… I’ve got a little bit of time to take care of myself! I’ll get to an end-of-year update in the near future, but in the meantime, I’d really like to do a little bit of UE4. It looks like there’s no way I’m going to be able to finish going through Section 4 by the end of year, but that’s what happens when life steam rolls your to-do-list 🙂

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

Lecture 105: Tank Control System
Lecture 106: Actors from Multiple Meshes
Lecture 107: Configuring a Tank
Lecture 108: 3rd Person Camera Control
Lecture 109: Fixing 3rd Person Camera Rotation

Lecture 105: Tank Control System

– iterative cycle: world->tank->controls->player2->UI->world
– keyboard/mouse/controller

Intention Manual Control Fly-by-wire Control Actuator(s)
Forward Symmetric Triggers Left Stick Forward (or W key) Both Tracks Forward – Same Speed
Backwards / Braking Symmetric Bumpers Left Stick Backward (or S key) Both Tracks Backward – Same Speed
Strafe N/A N/A N/A ( Tanks can’t strafe! )
Rotate Body Asymmetric Triggers/Bumpers Left Stick Left/Right (or A/D key) Tracks Different Speed
Rotate Turret N/A Right Stick to Aim (point with Mouse) Turret Rotation
Elevate Barrel N/A Right Stick to Aim (point with Mouse) Barrel Rotation

Lecture 106: Actors from Multiple Meshes

-You can add Sockets to your Static Meshes… this allows parenting of the turret mesh onto the body mesh
-Just attach the tracks, turret, and barrel here to the body using a blueprint

Lecture 107: Configuring a Tank

-No need for a DefaultSceneRoot component, just attach the Tank Body to the root to make it the new root.
-Enable Physics on the Tank and set a reasonable Mass
-Set this Tank to the Default Pawn
–Blueprints->GameMode->BattleTankGameMode->Create
–set the pawn
-Check the correct tank spawns on play
–if player start is intersecting the terrain, you won’t be able to spawn
–fixing this should make you spawn the tank when starting the game (camera still needs to be fixed)

Lecture 108: 3rd Person Camera Control

-camera gets attached to the player blueprint (Tank BP)
-attach the camera to a spring arm which we can manipulate
-create Input in the project settings for the “AimAzimuth” (https://en.wikipedia.org/wiki/Horizontal_coordinate_system)
-multiply the world delta seconds by the AimAzimuth axis value so that we can affect the Yaw of the Spring Arm’s Local Rotation (AddLocalRotation/split struct pin)
-multiply a variable so that we can increase the sensitivity of the rotation
-do the same to set up an “AimElevation” but with pitch instead of yaw
-rotations are compounding… we need to ensure a proper order of operations to that the two rotations are independent of one another (think gimbal)

Lecture 109: Fixing 3rd Person Camera Rotation

-by using a scene component as a child of the tank, we can set up a gimbal system to ensure the rotations stay coherent
-make the SpringArm a child of the Scene Component
-properly set up the AddLocalRotations to look at the elevation and azimuth with the scene component and the springarm
-on the spring arm, set “Inherit Roll” to false if you want to prevent the camera from tilting along with the tank when on a hill (ie: the camera will remain level with the horizon)