Nothing magic to it. You track the text and then use masking to cut awaythe peices you want obscured to create the illusion.
Motion tracking to make the text seem to be in the environment: Tracking and stabilization motion workflows in After Effects
Rotoscoping to composite the text behind elements in the shot: After Effects Help | Managing and animating shape paths and masks
All of these techniques involve creating a foreground matte of time type. The complexity of that matte depends on the complexity of the shot. This shot came from a game environment and it they had the 3D passes available you could separate foreground elements with a separate render pass and use that for a mask. If you are using footage and the camera move was nearly identical it would be easiest to stabilize the shot first so there is no camera movement, then add a colored solid to use as a track matte. The text layer could be added in position so you would know how much of the shot you needed to rotoscope. Then you set the blend mode (in this example a red solid set to multiply) so you can easily see the foreground elements. Then you rotoscope to create masks that just cover the parts of the foreground elements that you need to put in front of the text layer. When you have all of the masking done and any necessary animation is done to the masks to correct parallax problems you add a null and use an expression to tie the null to the stabilized layer, then parent the track matte layer and the footage to the null to remove the stabilizing from the shot and put that motion in the track matte. Then you could either use the track matte as a matte for the text or you could use a copy of the footage above the text layer and use the track matte for the footage. Using the footage will give you more options to correct the matte and do things like light wrap that make the composite more believable with less work.
Here's what it looks like after stabilizing (Not Warp Stabilizing) the shot and you are creating the roto (masks have been set to none to make it easier for you to see what I'm doing:
This is what it looks like with a duplicate of the footage and the track matte turned on: and part of the roto complete:
If you name the footage "stabilized" then you can use this animation preset to put the motion back in the scene and move the track matte: It looks like this:
Sometimes it will be necessary to use the Camera Tracker to add the text layer to the scene. You would still use the same masking technique to roto the foreground. If you have the opportunity to plan and shoot your footage before hand you can set up green screen panels where the text will go and use those to generate the mattes. You would also need a clean plate without the green screen panels in the shot that has the same camera movement.
Thank you for taking the time to do this Gerard. Much appreciated. I'm going to give this a shot tomorrow.
Also, do you have any helpful videos that you think could be useful? Doesn't have to specifically demonstrate what I'm asking but maybe demonstrate the techniques to accomplish an effect like this.
By chance, have you ever come across any video tutorials specifically demonstrating the effect I'm looking for?
Most tutorials that cover very specific effects aren't as useful as tutorials that cover general principles. If you understand the foundations of motion tracking and rotoscoping (which are covered in the resources I linked), you'll be a lot better suited to tackling the specific challenges in your specific project.