-
-
Notifications
You must be signed in to change notification settings - Fork 237
[WIP] Add Multiplayer Example #905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 25 commits
e3d63b7
3e8e3fa
96821ba
2931157
9eb685c
d3ab6b6
b814869
d14981c
33b7080
6098b09
30258c4
be54093
e1f74f9
0d0cc6e
71bab84
58c250f
e6e7210
2e69a8a
abc1612
2f9098b
57ea430
2e67f77
f67e73b
9cd0859
1f0dd45
f89291e
4116339
043db66
9679781
a1d7b30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Normalize EOL for all files that Git considers text files. | ||
* text=auto eol=lf |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Godot 4+ specific ignores | ||
.godot/ | ||
/android/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Multiplayer Lan Example | ||
|
||
This is a sample multiplayer example showing off how to set up a lobby + dedicated server with godot-rust. | ||
|
||
|
||
|
||
Largely adapted from FinePointCGI's Godot multiplayer tutorial: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we adapting youtube tutorial instead of one of godot's demo projects? https://github.com/godotengine/godot-demo-projects/tree/master/networking |
||
|
||
[Basics Of Multiplayer In Godot 4! - YouTube](https://youtu.be/e0JLO_5UgQo?si=mHYry88uC8j4r2DM) | ||
|
||
|
||
|
||
To run as dedicated server, run the exported version of this game from the command line with the arguments ``--headless --server`` | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://dmnqqew4xpfhw"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://4hxff102a1as" path="res://icon.svg" id="1_wn0vy"] | ||
|
||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_e3xmc"] | ||
size = Vector2(30, 6) | ||
|
||
[node name="Bullet" type="Bullet"] | ||
position = Vector2(1, -1) | ||
|
||
[node name="Icon" type="Sprite2D" parent="."] | ||
position = Vector2(14, 0) | ||
scale = Vector2(0.226563, 0.0390625) | ||
texture = ExtResource("1_wn0vy") | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
position = Vector2(14, 0) | ||
shape = SubResource("RectangleShape2D_e3xmc") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
[preset.0] | ||
|
||
name="Windows Desktop" | ||
platform="Windows Desktop" | ||
runnable=true | ||
advanced_options=false | ||
dedicated_server=false | ||
custom_features="" | ||
export_filter="all_resources" | ||
include_filter="" | ||
exclude_filter="" | ||
export_path="../../../../build/multiplayer Lan Tutorial.exe" | ||
encryption_include_filters="" | ||
encryption_exclude_filters="" | ||
encrypt_pck=false | ||
encrypt_directory=false | ||
script_export_mode=2 | ||
|
||
[preset.0.options] | ||
|
||
custom_template/debug="" | ||
custom_template/release="" | ||
debug/export_console_wrapper=1 | ||
binary_format/embed_pck=false | ||
texture_format/s3tc_bptc=true | ||
texture_format/etc2_astc=false | ||
binary_format/architecture="x86_64" | ||
codesign/enable=false | ||
codesign/timestamp=true | ||
codesign/timestamp_server_url="" | ||
codesign/digest_algorithm=1 | ||
codesign/description="" | ||
codesign/custom_options=PackedStringArray() | ||
application/modify_resources=true | ||
application/icon="" | ||
application/console_wrapper_icon="" | ||
application/icon_interpolation=4 | ||
application/file_version="" | ||
application/product_version="" | ||
application/company_name="" | ||
application/product_name="" | ||
application/file_description="" | ||
application/copyright="" | ||
application/trademarks="" | ||
application/export_angle=0 | ||
application/export_d3d12=0 | ||
application/d3d12_agility_sdk_multiarch=true | ||
ssh_remote_deploy/enabled=false | ||
ssh_remote_deploy/host="user@host_ip" | ||
ssh_remote_deploy/port="22" | ||
ssh_remote_deploy/extra_args_ssh="" | ||
ssh_remote_deploy/extra_args_scp="" | ||
ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}' | ||
$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}' | ||
$trigger = New-ScheduledTaskTrigger -Once -At 00:00 | ||
$settings = New-ScheduledTaskSettingsSet | ||
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings | ||
Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true | ||
Start-ScheduledTask -TaskName godot_remote_debug | ||
while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 } | ||
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue" | ||
ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue | ||
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue | ||
Remove-Item -Recurse -Force '{temp_dir}'" | ||
texture_format/bptc=true | ||
texture_format/s3tc=true | ||
texture_format/etc=false | ||
texture_format/etc2=false | ||
dotnet/include_scripts_content=false | ||
dotnet/include_debug_symbols=true | ||
|
||
[preset.1] | ||
|
||
name="Linux/X11" | ||
platform="Linux" | ||
runnable=true | ||
advanced_options=false | ||
dedicated_server=false | ||
custom_features="" | ||
export_filter="all_resources" | ||
include_filter="" | ||
exclude_filter="" | ||
export_path="build/linux/multiplayer-Lan-Tutorial.x86_64" | ||
encryption_include_filters="" | ||
encryption_exclude_filters="" | ||
encrypt_pck=false | ||
encrypt_directory=false | ||
script_export_mode=2 | ||
|
||
[preset.1.options] | ||
|
||
custom_template/debug="" | ||
custom_template/release="" | ||
debug/export_console_wrapper=1 | ||
binary_format/embed_pck=false | ||
texture_format/s3tc_bptc=true | ||
texture_format/etc2_astc=false | ||
binary_format/architecture="x86_64" | ||
ssh_remote_deploy/enabled=false | ||
ssh_remote_deploy/host="user@host_ip" | ||
ssh_remote_deploy/port="22" | ||
ssh_remote_deploy/extra_args_ssh="" | ||
ssh_remote_deploy/extra_args_scp="" | ||
ssh_remote_deploy/run_script="#!/usr/bin/env bash | ||
export DISPLAY=:0 | ||
unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\" | ||
\"{temp_dir}/{exe_name}\" {cmd_args}" | ||
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash | ||
kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\") | ||
rm -rf \"{temp_dir}\"" | ||
texture_format/bptc=true | ||
texture_format/s3tc=true | ||
texture_format/etc=false | ||
texture_format/etc2=false | ||
dotnet/include_scripts_content=false | ||
dotnet/include_debug_symbols=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://btw6ethmr2246"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this tmp file necessary to check in? |
||
|
||
[ext_resource type="Script" path="res://MutiplayerController.gd" id="1_omkav"] | ||
|
||
[node name="Control" type="Control"] | ||
layout_mode = 3 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
script = ExtResource("1_omkav") | ||
Address = null | ||
port = null | ||
|
||
[node name="Host" type="Button" parent="."] | ||
layout_mode = 0 | ||
offset_left = 74.0 | ||
offset_top = 120.0 | ||
offset_right = 251.0 | ||
offset_bottom = 168.0 | ||
text = "Host" | ||
|
||
[node name="Join" type="Button" parent="."] | ||
layout_mode = 0 | ||
offset_left = 270.0 | ||
offset_top = 120.0 | ||
offset_right = 447.0 | ||
offset_bottom = 168.0 | ||
text = "Join" | ||
|
||
[node name="StartGame" type="Button" parent="."] | ||
layout_mode = 0 | ||
offset_left = 479.0 | ||
offset_top = 120.0 | ||
offset_right = 656.0 | ||
offset_bottom = 168.0 | ||
text = "Start Game" | ||
|
||
[node name="LineEdit" type="LineEdit" parent="."] | ||
layout_mode = 0 | ||
offset_left = 156.0 | ||
offset_top = 68.0 | ||
offset_right = 508.0 | ||
offset_bottom = 99.0 | ||
|
||
[node name="Label" type="Label" parent="."] | ||
layout_mode = 0 | ||
offset_left = 75.0 | ||
offset_top = 70.0 | ||
offset_right = 122.0 | ||
offset_bottom = 96.0 | ||
text = "Name" | ||
|
||
[connection signal="button_down" from="Host" to="." method="_on_host_button_down"] | ||
[connection signal="button_down" from="Join" to="." method="_on_join_button_down"] | ||
[connection signal="button_down" from="StartGame" to="." method="_on_start_game_button_down"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://btw6ethmr2246"] | ||
|
||
[ext_resource type="PackedScene" uid="uid://bmxv4ilh115ct" path="res://testScene.tscn" id="1_2n0a4"] | ||
|
||
[node name="MultiplayerController" type="MultiplayerController"] | ||
game_scene = ExtResource("1_2n0a4") | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
|
||
[node name="HostButton" type="Button" parent="."] | ||
layout_mode = 0 | ||
offset_left = 74.0 | ||
offset_top = 163.0 | ||
offset_right = 251.0 | ||
offset_bottom = 211.0 | ||
text = "Host" | ||
|
||
[node name="JoinButton" type="Button" parent="."] | ||
layout_mode = 0 | ||
offset_left = 270.0 | ||
offset_top = 163.0 | ||
offset_right = 447.0 | ||
offset_bottom = 211.0 | ||
text = "Join" | ||
|
||
[node name="StartButton" type="Button" parent="."] | ||
layout_mode = 0 | ||
offset_left = 479.0 | ||
offset_top = 163.0 | ||
offset_right = 656.0 | ||
offset_bottom = 211.0 | ||
text = "Start Game" | ||
|
||
[node name="UsernameLineEdit" type="LineEdit" parent="."] | ||
layout_mode = 0 | ||
offset_left = 156.0 | ||
offset_top = 104.0 | ||
offset_right = 508.0 | ||
offset_bottom = 135.0 | ||
text = "Player" | ||
|
||
[node name="UsernameLabel" type="Label" parent="."] | ||
layout_mode = 0 | ||
offset_left = 75.0 | ||
offset_top = 106.0 | ||
offset_right = 126.0 | ||
offset_bottom = 132.0 | ||
text = "Name:" | ||
|
||
[node name="AddressLineEdit" type="LineEdit" parent="."] | ||
layout_mode = 0 | ||
offset_left = 156.0 | ||
offset_top = 55.0 | ||
offset_right = 508.0 | ||
offset_bottom = 86.0 | ||
text = "127.0.0.1" | ||
|
||
[node name="AddressLabel" type="Label" parent="."] | ||
layout_mode = 0 | ||
offset_left = 75.0 | ||
offset_top = 57.0 | ||
offset_right = 142.0 | ||
offset_bottom = 83.0 | ||
text = "Address:" | ||
|
||
[node name="MultiplayerLog" type="RichTextLabel" parent="."] | ||
layout_mode = 0 | ||
offset_left = 66.0 | ||
offset_top = 228.0 | ||
offset_right = 705.0 | ||
offset_bottom = 468.0 | ||
|
||
[connection signal="button_down" from="HostButton" to="." method="_on_host_button_down"] | ||
[connection signal="button_down" from="JoinButton" to="." method="_on_join_button_down"] | ||
[connection signal="button_down" from="StartButton" to="." method="_on_start_game_button_down"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[gd_scene load_steps=6 format=3 uid="uid://dp50474qin2xu"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://60wa7yj1fufb" path="res://art/playerGrey_walk1.png" id="2_h8a1g"] | ||
[ext_resource type="PackedScene" uid="uid://dmnqqew4xpfhw" path="res://bullet.tscn" id="2_niiqb"] | ||
|
||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_f0ham"] | ||
radius = 30.0 | ||
height = 70.0 | ||
|
||
[sub_resource type="CircleShape2D" id="CircleShape2D_paly2"] | ||
radius = 38.71 | ||
|
||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_c85fd"] | ||
properties/0/path = NodePath(".:sync_position") | ||
properties/0/spawn = true | ||
properties/0/replication_mode = 1 | ||
properties/1/path = NodePath(".:sync_rotation") | ||
properties/1/spawn = true | ||
properties/1/replication_mode = 1 | ||
properties/2/path = NodePath("GunRotation:rotation") | ||
properties/2/spawn = true | ||
properties/2/replication_mode = 1 | ||
|
||
[node name="Player" type="Player" groups=["Player"]] | ||
bullet_scene = ExtResource("2_niiqb") | ||
|
||
[node name="Sprite2D" type="Sprite2D" parent="."] | ||
scale = Vector2(0.5, 0.5) | ||
texture = ExtResource("2_h8a1g") | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
shape = SubResource("CapsuleShape2D_f0ham") | ||
|
||
[node name="HurtBox" type="Area2D" parent="."] | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="HurtBox"] | ||
shape = SubResource("CircleShape2D_paly2") | ||
|
||
[node name="GunRotation" type="Node2D" parent="."] | ||
|
||
[node name="BulletSpawn" type="Node2D" parent="GunRotation"] | ||
position = Vector2(53, 0) | ||
|
||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."] | ||
replication_interval = 0.1 | ||
delta_interval = 0.1 | ||
replication_config = SubResource("SceneReplicationConfig_c85fd") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forget newline