TIL: Learn to Code in C++ by Developing Your First Game (Section 3, Lectures 81-83)

Huh. I hadn’t really been paying attention. It turns out that Udemy has just changed their pricing strategy. Instead of allowing instructors to charge whatever price they wish for the content they provide, they now charge between $20 and $50 per course. This means that the Learn to Code in C++ course is now a mere $35. I can’t help but feel mildly agitated at having backed the course for £45 on Kickstarter now that I know I could have spent less. That said, I’m glad that Ben got the funding he asked for, and I feel that this has been the best course I’ve taken. So… I’ll try not to get too disgruntled.

As a side note, I’m now on the fence about what that means going forward with my own plans. I had it in my mind that I was going to produce some Houdini training material for the website… but now I’m not so sure it’s worth while when I can’t price at what I feel to be an appropriate rate. Or maybe instead of developing a “proper” curriculum I would need to break it up into digestible chunks for a smaller price point? It feels like a shame that people will be limited to buying piecemeal courses for a low price. But I guess it just means that teachers will need to migrate to a different platform going forward.

At any rate, I didn’t get as much done today as I’d hoped, but it was a good day nonetheless.

Section: 3 – Building Escape – Your First Unreal / C++ Game

Lecture 81: Using Physics Handles

-Again, we’re talking about the Physics Handle.
Red, Green, Refactor
-Ctrl f -> search entire solution can help us find code that already exists when the documentation is shit

In our case, we an snag the “GrabComponent(ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), true);” and repurpose it.

ComponentToGrab is undefined; we need to figure out what our GetFirstPhysicsBodyInReach() method is doing so that we can pass information to ComponentToGrab.

Right now, we’re in “get it working” mode (green) not refactoring mode. GSD = Get Shit Done. We need to A: create a piece of data associated with GetFirstPhysicsBodyInReach(), so auto HitResult = GetFirstPhysicsBodyInReach(); Then we ensure that GetFirstPhysicsBodyInReach() is returning the correct data (Hit). And then, back in UGrabber::Grab() we create auto ComponentToGrab = HitResult.GetComponent();

Since we also need to only do this if we hit something, then we compensate for that too: auto ActorHit = HitResult.GetActor();

You can bring the line trace code up, and use the position with PhysicsHandle->SetTargetLocation(LineTraceEnd); so that if (PhysicsHandle->GrabbedComponent) we move the physics handle to the line trace end.

PhysicsHandle->ReleaseComponent() can be used in the Release() so that we can drop our object after grabbing it.

One advantage that I’m seeing in this method over what I tried last year on my own, is that since the character is not a physics object, we don’t just cause stuff to knock over when stepping into it. Can’t believe that didn’t occur to me.

Lecture 82: Refactoring Rules

– fewer lines of code is better
– naming schemes are important to keep things self documenting
– comment “why”
– “what” should be obvious

When refactoring, it can be handy to pre-comment your source control check-in so that you are more likely to only treat the commit as refactoring.

It’s unnecessary to source control the .sln file, so it was added to the ignore file.

We don’t want to find the player’s look-at directly in the Tick Component… it’s better to keep it as a separate method so we can keep TickComponent readable, and call on the method elsewhere if necessary rather than literally duplicating code.

Lecture 83: Introducing Unreal’s TArray

TArrays – contain many elements of the same type

Right now, the only Actor that can open the door is the default pawn, but we want it to be based off of mass. We need the pawn to have some mass so that we can 1. trigger the plate as a result of mass, 2. not float in the air.

By Adding an eye height (60) and enabling physics (70kg) it seems that the character is now able to receive impulses of energy from the physics objects. This seems bad, and buggy… but I’m not sure exactly how to counter it.

We want to add a GetTotalMassOfActorsOnPlate() where we store a float TotalMass and accumulate the mass of anything colliding with the trigger.

We will need to use PressurePlate->GetOverlappingActors() in order to find the overlapping actors. We need a TArray of the Actors in order to pull this off, so we create TArray<AActor*> OverlappingActors;

Because GetOverlappingActors() is using references, we can assume that we need OUT parameters. Therefore we will #define OUT to help annotate the code.