Skip to content

Appendix D. Moving mirrors

While there are tutorials on YouTube or just online guides for creating mirrors in Godot, those are mostly for static mirrors. In one of my personal projects I needed a moving mirror however. The problem is that most tutorials use a Subviewport which doesn't include a position property. This means that it won't matter no matter where you put it in the hierarchy. I am not going to add the full step by step tutorial on how to make moving mirrors, since the most fundemental steps are aleady covered by other online videos by others like this one.

The only missing part is positioning the camerea where you want and attaching an extra script to it in order to configure a node to follow. Below is the script I am using in my personal project.

public partial class MirrorCamera3d : CleanCamera3DNode
{
    [Export]
    public Node3D NodeToFollow { get; set; }

    public override void ProcessFrame(double timeElapsedSincePrevFrame)
    {
        if (NodeToFollow == null) return;

        GlobalBasis = NodeToFollow.GlobalBasis;
        GlobalPosition = NodeToFollow.GlobalPosition;
        GlobalRotation = NodeToFollow.GlobalRotation;
        Rotate(Vector3.Up, Mathf.DegToRad(180));
    }
}

Note however that CleanCamera3DNode is not a class in Godot, but a wrapper around the Camera3D class. It's basically the same as CleanNode3D from this tutorial. Instead of replacing _ProcessFrame & _OnReady for Node3D it replaces the ones for Camera3D.