To prevent the weapon disappearing into the wall when we are up against it we will introduce a new node called a SubViewport
A subviewport node is a tool used in game development that renders a separate rectangular region of a scene independently of the main screen.
Add a SubViewportContainer node
Place it above the CenterContainer
Add a Subviewport as a child of it
Add a Camera3D as a child of Subviewport
Rename the Camera to WeaponCamera
Select the SubviewportContainer node
Set the Anchor preset to Full Rect
Select the Subviewport node
Problem: we have two cameras looking at the same weapon model but moving differently (different transforms.)
Solution: The RemoteTranform3D node
What is the RemoteTransform3D Node?
It is a special node that pushes its own transform (position, rotation, and scale) to another node in the 3D scene. It allows a node to follow the transformations of a "remote" node instead of its parent node. This is useful for detaching a node from its parent's hierarchy to control its movement independently, such as making a camera follow a player character even if the player object is deleted, or making an object follow a path.
Select the SmoothCamera node in the Player scene
Add a RemoteTransfer3D node as a child
Select the RemoteTransform3D node
Assign the WeaponCamera node
Basically we have pinned the WeaponCamera
We can still see two guns though
We only want the weapon camera to see the gun
Only enable layer 2 on the cull mask
Right-click on the SMG model
You can now see the child components
Their text is an orange / yellow colour
Now select ALL the children
Put them ALL on Visual Layer 2
Return to the Player scene
SmoothCamera can no longer
Select the WeaponCamera node
Set the FOV to 40 degrees
Change the z position to -1.8m
This gives us more room for the gun
Select the MuzzleFlash node
Position it at the new end of the muzzle
Test the game, the weapon no longer clips through walls