endlessm / moddable-platformer

Mini moddable platform game to ease the Godot learning curve
https://godotengine.org/asset-library/asset/3371
MIT License
12 stars 0 forks source link

Add multiplayer camera #9

Closed manuq closed 2 weeks ago

manuq commented 2 weeks ago

In the Moddable Platformer, we would like the ability to show multiple players on screen at once. We can probably get away with a camera which zooms and pans to contain all of the players. Ideally this should happen "for free": the camera we have built in to the game should understand how to follow however many players exist in the scene.

wjt commented 2 weeks ago

Implemented in #12.

wjt commented 2 weeks ago

As of commit a1d098c4, starting from a clean working copy, I did the following, following the steps described in MODS.md:

Click on the Player node. In the inspector, try changing the Player dropdown to "Two" or "Both".

I think this property is confusingly-named. Selecting "Two" works fine, modulo Dvorak Problems that I'll open a PR for.

Duplicate the Player node.

image

Move it next to the existing player.

image

Then change the Player to "Two" in the duplicated one. Now the game is multiplayer.

I get this crazy flickering effect:

Screencast from 2024-11-12 09-50-12.webm

I think what's happening is that the players are intersecting so they're doing some weird collision. I guess the instruction above didn't mean “move it next to the existing player in the scene tree” but “move it in the canvas so that it doesn't overlap the first player”.

You will notice that the camera is following one of the player characters. So try disabling the Camera2D node that's a child of the Player node.

Both players have a camera because duplicating the player duplicates its children too.

And then enable the MultiplayerCamera node that's at the bottom of the Scene Dock.

Very nice!

wjt commented 2 weeks ago

I had a quick poke around to see if there's some way to make the players overlapping automatically fix itself but it got pretty nasty pretty fast. Maybe it's a fun thing for learners to find for themselves. I tweaked the documentation in #13.