0 votes

For a splitscreen-game I want to render the game from each player's perspective and arrange these renders next to each other on the screen. I tried to solve this based on the 3D-in-2D-Demo project: Each player has a camera within a viewport. Those viewports' textures are rendered to sprites. But viewports are capturing, meaning they only render their (direct or indirect) child nodes. But I cannot make the game map a child of both viewports at the same time.

How can I tell the viewports to both render the map?

This is my node structure:

+ Game (regular "Node")
|-- Map (floor, walls etc.)
|-- Players (Spatial)
|   |-- Player 1 (Spatial)
|   |   |-- KinematicBody
|   |   |-- Viewport
|   |        |-- Camera
|   |-- Player 2 (Spatial)
|       (same as Player 1)
|-- Sprite 1
|   (using Viewport of Player 1 as texture)
|-- Sprite 2
    (using Viewport of Player 2 as texture)

I also tried following this tutorial: https://www.youtube.com/watch?v=WhCQABLmEv0 but it's for Godot 2 and I cannot get it to work with Godot 3.

I am using Godot 3.0.5 both on Linux x64 and Windows x64.

in Engine by (47 points)

After grepping through the example projects for "Viewport" I found that the "Interactive Cubes" demo seems to do kind of a splitscreen-implementation. It seems to duplicate the whole scene, but only as a linked Scene, so I guess that is okay and good style? (usually I do OOP or functional; node-based design is still quite new to me)

Anyway, I'll fiddle around and let you know if I get it working.

1 Answer

+3 votes
Best answer

Okay, I was totally on the wood way with everything concerning Viewports.

Viewports render the whole scene, not only their children

The problem was that I had the camera as a child of the player kinematic body to be able to set its position relative to the player. When I replaced the Camera by a Viewport with a Camera, the relative spatial transformation got lost; I suspect because Viewport is not a Spatial node and that makes it lose relative positioning. This also explains why the tutorial video had to create dummy cameras under the car node and on every step update the real camera's (the one in the Viewport) transform with the global transform of the dummy camera.

Viewports as non-Spatial-nodes prevent relative positioning of child nodes to parent nodes of the Viewport.

Finding the source of my problem has taken me several days now. There really should be at least a hint in the Viewport doc about this. Better even: The editor could display a warning sign, if a hierarchy of Spatial nodes is interrupted by a non-Spatial Node because this loses the ability to position relatively to the parent Spatial.

by (47 points)
selected by

There really should be at least a hint in the Viewport doc about this.

Better tell the documentation team about that one.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.