How to create a local split screen 2 Player platformer ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ulty
:warning: Old Version Published before Godot 3 was released.

I’m trying to create a simple 2D split screen platformer, which supports 2 players that have each their own camera following them. I think I have to use multiple viewports with a shared world but have no idea how to set this up.

Could someone give a basic example on how this would be done ?

:bust_in_silhouette: Reply From: KRL

For 3D it looks like this:

  1. Add panel element and place it and resize so it matches your desire
  2. Add a ‘Viewport’ to panel as child
  3. Add ‘Camera’ as child to the viewport
:bust_in_silhouette: Reply From: reeve

To create a split screen you need 4 scenes.
Scene one is your game scene with the world and all game objects including the player objects.

The second scene you create is the view. At this scene you need a Node as root element. This root element need two Panels. At this Panels we draw the game. That’s the reason why you must organize the position and size as the splits screen should look like.

The next step is to create two scenes. You need this scenes to connect your world with the view. The root node of this two scenes are a Viewport. The Viewport at the scenes has two Children. As the first children you add your game world and second children is a camera.

Now you must write a little script for the camera. At this script you say what object you want look with the camera. Scene one with viewport and camera one should look to player one.Scene two with viewport and camera two should look to player two.
Next you activate the current point at your cameras.

At the last step you go to your view scene and add at the Panel, which should show player one, the scene where the camera is focused at player one.
Now you make the same thing with the Panel which should draw the world around player two. Add to the Panel the scene where the camera is focused at player two.

If I have say clearly what I mean and you have all done correct, you should have a split screen. At the moment it is the easiest way to create split screen that I know.

That’s quite a good high level description of what you need to do to get a split screen setup working, but for the ‘game scene’ itself, I found that it’s better to make it an autoloaded scene, than just add it to the scene with the player-n camera directly.

Otherwise you can end up with duplicates of game scene objects and data.

dynamite-ready | 2018-04-14 18:01

:bust_in_silhouette: Reply From: volzhs

I’m not sure when it’s implemented but there is a plan for this.

I have seen this and I Hope this implementation comes very fast.

reeve | 2016-08-08 19:46

:bust_in_silhouette: Reply From: JTJonny

Good news its now possible to splitscreen in 2d!

(from facebook.com Godot Group page)

Juan Alpaca
September 14 at 2:01pm

User Faless (sorry man, no idea what your real name is) fixed Viewport to make it easier to do 2D split screen, so I copiend and added a couple lines of code to the platformer demo to make it split screen too. It's pretty straightforward.

You can get it from godot-demos repository, and you need latest Godot head.

Thanks for the link.

JTJonny | 2016-09-17 19:42

Link broken… any updated link?

duke_meister | 2018-07-08 12:46

I updated the godot 3 demo project (pull request) but there’s also a full tutorial on how to do this in godot 3 at kidscancode’s blog.

markopolo | 2018-08-16 14:29

There is now also an example in the official repository:
https://github.com/godotengine/godot-demo-projects/tree/master/viewport/dynamic_split_screen

st_phan | 2023-04-11 21:00

:bust_in_silhouette: Reply From: OnyDeus

This has changed for 3.0.
The simplest Node setup to achieve this in 3D is as follows:

Root Node
|ViewportContainer New for 3.0
||Viewport
|||Camera
|ViewportContainer2
||Viewport
|||Camera

To make this functional, I had to set Stetch property on for both ViewportContainers.

This will work when the project is played. The ViewportContainers appeared black in the 2D editor view until Godot was closed and re-opened. Only then would it display properly when editing.