How do I change aspect ratio without stretching image or changing center of screen?

Godot 4.4

After following this tutorial for using pixel perfect sprites with camera smoothing I have it working just as in the video but as it is in there I didn’t see a way to support other aspect ratios which I would like to do for my project if I implement this. I wanted to do it without stretching so it didn’t distort the image so I just tried changing the size of the subviewport to match other aspect ratios like 21:9, and it does increase the size but in doing so also changes the position of the center of the screen but I would rather the character stay at the same point on screen.

Having said all that, basically my question is with a system like that is there a way to increase the window size for other aspect ratios while keeping the camera centered on the same location? I tried manually changing the position of the camera and subviewportcontainer when I toggled the aspect ratio increase but it didn’t really affect anything I could notice. Also tried changing anchor settings, fill settings, and stretch settings in the container node but couldn’t get anything working without stretching the pixels which isn’t really what I wanted. I’ll include some screenshots of the test project to show code added to the tutorial and the node setup and everything.

Also as a side question, why is the unused area grey in the test project, I thought any area not covered by a viewport used black boxes or am I misunderstanding that and black boxes are based on window sizing?


Ok it was very late when I posted that so I now realize that it is centered in both, the game is just offset. So now my only question is why are there no black bars on the project and I suppose how could I center the viewport as well because anchors didnt work?