Basics of Multiplayer in Godot 4! C# Godot Basics!
Вставка
- Опубліковано 29 чер 2024
- Subscribe and learn more from me about Game Development and Programming!
In this video, we discuss how to use Godot 4s New Multiplayer System!
Explore the exciting features of Godot 4's new multiplayer system in our latest tutorial! In 'Basics Of Multiplayer In Godot 4,' we break down the essential concepts and provide step-by-step guidance to create engaging multiplayer experiences in your game. Whether you're a beginner or an experienced developer, this video will equip you with the knowledge and skills needed to leverage Godot 4's innovative multiplayer functionalities. Dive in now to take your game development to the next level!
Links:
Starter Project: github.com/finepointcgi/Basic...
Finished Project: github.com/finepointcgi/Basic...
CyberPunkTileSet: chroma-dave.itch.io/neon-city...
Assult Rifle Tile Pack: cosmiconion.itch.io/modern-as...
File Zilla: filezilla-project.org/downloa...
Putty: www.putty.org/
Digital Ocean: m.do.co/c/4ca0a2e54d02
BE MY FRIEND:
🐦Add me on Twitter: / finepointcgi
Check out my Website: finepointcgi.io/
Have a Suggestion? github.com/finepointcgi/Finep...
You can support me on Patreon: / finepointcgi
Hang Out with the Guys on Discord: / discord
TIMESTAMPS
00:00:00 - Start
00:00:36 - Discussing Assets
00:17:35 - Creating Our Connection Base Scene
00:20:06 - What All the Different Signals Do in Multiplayer
00:24:40 - How To Host Your Game (Make a Server)
00:31:06 - How To Join a Game
00:34:20 - Why Does the ID One Exist?
00:35:21 - Marker 7
00:37:18 - Discussing RPC Calls
00:42:17 - RPCS Are Strange in C#
00:43:18 - Sending Player Information Over to My Server/Clients
00:51:49 - Lets Chat About RPC ID
00:54:43 - Spawning Our Players
01:01:28 - Let’s Talk About How To Sync Players Using the Multiplayer Synchronizer
01:10:23 - Talking About Bandwidth
01:17:16 - Getting Shooting To Work
01:18:43 - Making Our Bullets Disappear After Some Time
01:19:22 - How To Show the Players Name
01:20:42 - How To Handle Disconnections
01:25:14 - How Can I Do a Dedicated Server
01:31:09 - How Do We Host Our Game?
01:39:37 - Turns Out Dlls Are Important
01:41:03 - Outro
MUSIC
Music provided by TheRelaxedMovement.
Check it out here: / therelaxedm. .
HASHTAGS:
#Godot4 #Multiplayer #gamedev
ABOUT MY CHANNEL:
I've been a software developer for over 7 years. I've worked in the game industry for 3 of those years. This channel is used for news on the gaming\programming industry and for tutorials for game\programming development.
Basics Of Multiplayer In Godot 4! csharp
Keywords: Godot 4, Multiplayer, Game Development, Tutorial, Multiplayer System, Game Design, Networking, Godot Engine, Online Gaming, Game Programming, Indie Development, Game Creation, Network Programming, Real-time Multiplayer, Interactive Gaming
Its nice if you use Rpc(nameof(startGame)) instead of Rpc("startGame") so you dont have to rely on hardcoded method names, and if u eventually need to change the method name you don't need to worry about changing strings in the code.
When using nameof you can also use IDE tools, such as finding method references, etc.
I didn't know that existed. That's really cool thanks!
You call also do Rpc(MethodName.StartGame), you also have this for signals (SignalName.Pressed) for a button, for example
This is a great tutorial. I ran into an issue testing external network connections over the Internet. Turns out that my router wasn't allowing me to "connect to myself" over the Internet, but when I got a friend to test from an actual external network location, it worked totally fine. Having fixed that problem, it seems to me that pretty much everything shown in this video is accurate and working in the current version of Godot 4.
Hey I'm glad it worked for you!
oh this is amazing! I have tested some multiplayer in godot in a 3D project that I am working on. I was surprise how easily it was to set everything up. the server, the client side. I even used rcp calls to gain skill info from the server and that kind of stuff. Sync of movement was an issue and I dropped multi after that test. I still need to figure many other core mechanics of my game before bothering with multiplayer but still. Godot has huge potential on it for sure.
Thanks so much for this tho! gonna for sure check it!
That's one of the coolest things about Godot multiplayer is relatively easy. Non-server multiplayer WebRTC is quite a bit more complicated but it is easier than other engines that's for sure!
First of all thanks for the great tutorial, it was really useful right till the end where you explain how to host the game on DigitalOcean. I have newer hosted a game and was wandering could you show us how to use your droplet since I am not shore i would like to pay for hosting just to test the game with a friend or two :(
Huge thanks in advance!
Amazing
What is the thing showing your inputs (mouse clicking, arrows) during the video? Also: Thanks for not editing out the pitfalls, this is the stuff where one actually learns something.
Amazing video! I learned a lot about multiplayer thnks a lot!
Actually i think the multiplayer in the same project can be better if we manage it in an Autoload in that case the system will let us change between scenes without problem. IDK if I'm right but it's just an idea
And i have a question, is it hard to make a server for our game that doesn't contains the game?
Sometimes i make Minecraft servers, and the file of the server is no the same as the game i think it works to let all the users mount their own servers and make an exe lighter than the game I guess, if u have an idea can u explain it?
And one more question, is any way to send args to our project inside Godot? to play the server without export it?
If you want something similar for a top down game, I used this (Also I have my own changes, I have move_ instead of UI and I have MoveSpeed instead of Speed) - Also velocity is normalized so diagonal movement isn't faster:
Vector2 velocity = Velocity;
Vector2 direction = Input.GetVector("move_left", "move_right", "move_up", "move_down");
if (direction != Vector2.Zero)
{
velocity.X = direction.X * MoveSpeed;
velocity.Y = direction.Y * MoveSpeed;
}
else
{
velocity.X = Mathf.MoveToward(Velocity.X, 0, MoveSpeed);
velocity.Y = Mathf.MoveToward(Velocity.Y, 0, MoveSpeed);
}
Velocity = velocity.Normalized() * MoveSpeed;
MoveAndSlide();
Please make tutorial for multiplayer 3D 🥺 I haven't seen any video's on UA-cam about this
You can use this tutorial if you know how to make basic 3D game. I have followed this using 3d project and only issue I ran into was players stealing each others cameras(since I did first person muliplayer) and i fixed it with camera.Current = true, so I don't think you would run into many problems either!
Nice tutorial. Thank you for sharing!
Good multiplayer tutorials are super rare. big problem is they are also often very long.
The buttons pressed overlaying use is a bit irritating.
A tutorial on basic interaction and / or enemy handling would be nice! Or best practices for node architecture when working with multiplayer.
I'm def hit and miss on that overlay.. I'll take a poll and see what people want.
I will add them to my list! Can you give me more details on the tutorials?
Im at this point of the tutorial 34:17 and i checked my code, apparently its all good, but then when i click play, nothing happens, it seems like is not even detectin when i click the button... someone else with that issue?
Nevermind, it was my mistake, i didnt connect the buttons hahaha
How do you properly close a server? If say I wanted to restart it. Because CloseConnection() doesn't exist for c# it seems, closing godot is the only time i can close the server and restart a new host it seems?
Very nice Tutorial, but I have a question.
I want to test the game from computers in diffrent LANs, so the IP Address must be public.
First i write my global, unique IPv4 address in the export variable Address (Scene Multiplayer Controller).
Than I host it first. All seems good.
But when I want to join, it didnt find the host.
Is it becuase the port on my router is blocked or is it something else?
Correct using this method your firewall is goign to block it.
could you cover MultiplayerSynchronizer visibility?
I want to but the docs are not clear at all how it works so it may take some time for me to figure out how it works..
@@FinePointCGI exactly, I've bee struggling to find a basic example.
was thinking maybe a game of pong but with walls that obscure the ball and the other player.
Will you make part two for GDscript?
I plan to. Every single tutorial I make I usually do a C# version right after the GD version. For instance I am recording a GD version of a LAN server browser by using udp and ping casting so I'll be making a C# version of it right after.
As for a part 2 what would you like to see currently I would like to have a WebRTC multiplayer tutorial but is there anything specific that you want in a part 2?
@@FinePointCGI You are awesome, My request is to set up a room and let others join the room with that room name. Can you make it ? Every player can choose their colors those colors are red, yellow, blue and green.
@@bertangokalp9002 I can put it on my list... When it comes to a room usually that means you want to use WebRTC since WebRTC has the capability to build out rooms..
@@FinePointCGI You are the best Godot UA-camr in this world 🌍
I'm trying to test if I can connect to my local host and I keep getting CONNECTION FAILED when I press join game. I made sure the code, address, and port is correct but no luck.
Try running Godot in command line mode and see if any additional error show up.
If you downloaded it from the website just go in and click on the bat file that gets downloaded with it and it should show the command prompt. From there you should be able to debug
@@FinePointCGI It was my mistake, I was pressing host then join on the same instance. I needed to go to the other instance and press join. I never did anything with multiplayer so I thought the host had to join the server once it was created. Thank you for your help.
Hello
Hello
This tutorial is deprecated.
It's Godot 4.2.2 and they already removed and rewrote stuff.
Smh, I barely find this engine stable at all with all these changes.
The engine is already left behind with quality documentation in comparison to Unity/Unreal.
And now they break backwards compatibility in anyway. And their decisions to change the API's surface make no sense.
For example, before you had method "create_server(adress, port)". Now you can only pass port as parameter as the server automatically picks some ip from the spectrum "0.0.0.0". If you want to bind an IP yourself you have to call a setter on the peer object "set_bind_ip(adress)". What is the purpose of this? Before was good enough, in fact better, as this is how every socket in initialized in every programming language.
Godot's concept is great, but the direction the engine is taking starts to decline. They rush buggy features, they change things that could very well stay the same. When you improve a car, you modify the engine's internals, you don't switch the steering wheel from left to right side too.
Great tutorial anyway.
Sad that I am not finding my place in this engine anymore.
I better write my own stuff, much easier to deal with than fighting ages with outdated tutorials and trying to grasp illogical syntax.
Thank you for the complement on the tutorial!
Godot does have a major problem with depecateing code at a whim. Its become very painful to create tutorials because they go out of date so fast.
In this case when you do create server it picks the ip of the machine your on by default in the tutorial i use
server = ENetMultiplayerPeer.new()
var error = server.create_server(port, 2)
if error != OK:
print("cannot host: " + error)
return
server.get_host().compress(ENetConnection.COMPRESS_RANGE_CODER)
multiplayer.set_multiplayer_peer(server)
print("Waiting For Players!")
and in 4.2.2 it works it binds to the ip and nothing was outdated that I can see.
"create_server(adress, port)" was done in 3.2 and removed in 4.0.
@@FinePointCGI Thank you too for feedback on my comment !
Hello:P I spoted some bug... if u set max player to more than 2 players and more than 2 players are connected wierd things start to heppen like players are duplicated and instead of lets say 4 players i am getting 8 spawned... godot shows also error in Player.cs -> E 0:00:25:0541 void System.Number.ThrowOverflowOrFormatException(System.Number+ParsingStatus, System.TypeCode): System.FormatException: Input string was not in a correct format.
System.FormatException
:0 @ void System.Number.ThrowOverflowOrFormatException(System.Number+ParsingStatus, System.TypeCode)
:0 @ void System.Number.ThrowOverflowOrFormatException(System.Number+ParsingStatus, System.TypeCode)
:0 @ int System.Int32.Parse(string)
Player.cs:18 @ void Player._Ready()
Node.cs:2117 @ bool
I found whats wrong... function sendPlayerInformation is wrong... somehow it duplicates playerInfo for all joining players besides host and last joined player so lets say if there is 5 players then player 2,3,4 are duplicated * number of all players... u can see this by printing item in GameManager.Players when game is running (i dont know why becouse !GameManager.Players.Contains should check if it already exists) so for only 2 clients i seems to be ok but for more players its wrong... i fixed it like this
i recoded function that server is storing information about all players and when all are ready then before gameStart server sends all players information to each client when sending is ready then all clients starts game (bug exists only in c# version in GD script all is ok)
I'm getting this too, did you ever find out the bug? On mine when I spawn 3 players (let''s call them A (host), B and C) I get weird behavior. For A and C everything is fine but for B it spawns duplicates of A and B in the center of the map (not a spawn point) and they have a generic name. The name is what the error is talking about because in Player._Ready() it's trying to parse what's supposed to be an int but is instead the generic type name (CharacterBody3D in my case). For the life of me I can't figure out where the GameManager is getting these extra players.
Yes i found bug and i posted solution... and Day after it was deleted... game manager is ok problem is in send Player information function it is replicating every data betwean first and last Player... my solution was first Connect all players and they send data only to host when all are ready then before startgame i send data to all other clients and iam waiting for answet if Player list is created then start game on every client
@@joannagrzybek8126Wow thanks for the lightning fast reply! I had a feeling there was something there. I will take a look - thank you!
Wanted to leave my solution in case other folks have the same issue. So I'm not sure entirely what was happening but I suspect that the contains check: if (!GameManager.Players.Contains(playerInfo)). Was not working as intended and actually caused the duplication to happen. My fix was to change this check to a LINQ function that checks for the specific id and if it's not found then add the PlayerInfo to the game manager. I'm still pretty new to C# so I don't know if it's the best solution.
// This was my solution. I need to come up with a better name for "fromList" 😅
var fromList = GameManager.Players.FirstOrDefault(i => i.Id == id);
if (fromList == null){
GameManager.Players.Add(playerInfo);
}
i get something like this:
E 0:00:16:0684 on_sync_receive: Ignoring sync data from non-authority or for missing node.
Condition "true" is true. Continuing.
modules/multiplayer/scene_replication_interface.cpp:873 @ on_sync_receive()
but the problem is this way you setup things is client authority, multiplayer games are usually done by server authority, to prevent some forms of cheating. is there a way to setup server authority in godot? there must be a way
I'll be looking at a dedicated server tutorial soon. It's on the list along with user management and saving