Divided screen in a 2D world. Conflicting viewports with game stage?

Godot Version



I’m trying to create a test project implementing a divided screen format. I put two SubViewports inside their respective viewport container, and aligned each one to fit half of the screen. Then I put a camera inside both of them, and two sprites outside, as siblings of the viewport containers, which are meant to be the characters of each player. Then in the _ready() function I set both viewports’s world_2d property to the world_2d of the root viewport, and in the _process() function I set everything up for each viewport’s camera to follow its respective character.

The problem comes when the sprites are shown in-game, because the viewports acts as “mirrors” to the characters, resulting in them being duplicated in the screen while happening very weird visual effects as they move. I evade this problem if I put all the elements of the game, including the characters, in some place distant to the visible screen, remaining visible only the viewports, or if, on the contrary, I put the viewports far away from the visible screen and use a camera on the root viewport to focus on them.

However, any of this has the same problem: the posibility of one player going to the viewport’s region and then being shown on top of the cameras. Even if this the scene is designed to make it impossible, or if I instantiate the viewports as a different scene, I had to manage two elements separated in the game area: the viewports and the actual game stage, which I think is a bad practice. How could I make it better?