Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions networked_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var _rotation_id := -1
func _ready():
# Notify the NetworkSync who is controlling parent nodes.
NetworkSync.set_node_as_controlled_by(get_parent(), self)
NetworkSync.register_variable(get_parent(), "translation")
NetworkSync.register_variable(get_parent(), "position")
NetworkSync.register_variable(get_parent(), "velocity")
NetworkSync.register_variable(get_parent(), "on_floor")
if not get_tree().get_multiplayer().is_server():
Expand Down Expand Up @@ -118,21 +118,22 @@ func _collect_epoch_data(buffer: DataBuffer):
buffer.add_vector3(get_parent().mesh_container.rotation, DataBuffer.COMPRESSION_LEVEL_2)


func _setup_interpolator(interpolator: Interpolator):
# Called only on client doll to initialize the `Intepolator`.
_position_id = interpolator.register_variable(Vector3(), Interpolator.FALLBACK_NEW_OR_NEAREST)
_rotation_id = interpolator.register_variable(Vector3(), Interpolator.FALLBACK_NEW_OR_NEAREST)
#func _setup_interpolator(interpolator: Interpolator):
# # Called only on client doll to initialize the `Intepolator`.
# _position_id = interpolator.register_variable(Vector3(), Interpolator.FALLBACK_NEW_OR_NEAREST)
# _rotation_id = interpolator.register_variable(Vector3(), Interpolator.FALLBACK_NEW_OR_NEAREST)


func _parse_epoch_data(interpolator: Interpolator, buffer: DataBuffer):
# Called locally to parse the `DataBuffer` and store the data into the `Interpolator`.
var position := buffer.read_vector3(DataBuffer.COMPRESSION_LEVEL_0)
var rotation := buffer.read_vector3(DataBuffer.COMPRESSION_LEVEL_2)
interpolator.epoch_insert(_position_id, position)
interpolator.epoch_insert(_rotation_id, rotation)
#func _parse_epoch_data(interpolator: Interpolator, buffer: DataBuffer):
# # Called locally to parse the `DataBuffer` and store the data into the `Interpolator`.
# var position := buffer.read_vector3(DataBuffer.COMPRESSION_LEVEL_0)
# var rotation := buffer.read_vector3(DataBuffer.COMPRESSION_LEVEL_2)
# interpolator.epoch_insert(_position_id, position)
# interpolator.epoch_insert(_rotation_id, rotation)


func _apply_epoch(_delta: float, interpolated_data: Array):
# Happens only on doll client each frame. Here is necessary to apply the _already interpolated_ values.
get_parent().global_transform.origin = interpolated_data[_position_id]
get_parent().mesh_container.rotation = interpolated_data[_rotation_id]
func _apply_epoch(_delta: float, _interpolation_alpha: float, past_buffer: DataBuffer, future_buffer: DataBuffer):
pass
# # Happens only on doll client each frame. Here is necessary to apply the _already interpolated_ values.
# get_parent().global_transform.origin = future_buffer[_position_id]
# get_parent().mesh_container.rotation = future_buffer[_rotation_id]
4 changes: 2 additions & 2 deletions world.gd
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func _on_client_disconnected(peer_id):
rpc_id(_players[player_id][&"peer_id"], &"_remove_player", disconnected_player_id)


@rpc(call_remote, any_peer, reliable)
@rpc("call_remote", "any_peer", "reliable")
func _spawn_new_player(player_id, peer_id):
print("Spawn player id: ", player_id, ", Peer_id: ", peer_id)
print("While my peer id is: ", get_tree().get_multiplayer().multiplayer_peer.get_unique_id())
Expand All @@ -92,7 +92,7 @@ func _spawn_new_player(player_id, peer_id):
player.set_color(COLORS_LIST[player_id])


@rpc(call_remote, any_peer, reliable)
@rpc("call_remote", "any_peer", "reliable")
func _remove_player(player_id):
var player_node = get_tree().get_current_scene().get_node("player_" + str(player_id))
if player_node != null:
Expand Down
45 changes: 23 additions & 22 deletions world.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ volumetric_fog_density = 0.1293
[sub_resource type="BoxShape3D" id="6"]

[node name="World" type="Node"]
script = ExtResource( "2" )
script = ExtResource("2")

[node name="DirectionalLight" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.0134716, -0.995255, 0.0963678, -0.13779, 0.0973049, 0.98567, -0.99037, 3.38571e-08, -0.138447, 0, -5.26483, 0)
Expand All @@ -41,92 +41,93 @@ collision_mask = 3

[node name="CollisionShape" type="CollisionShape3D" parent="StaticBody"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
shape = SubResource( "1" )
shape = SubResource("1")
disabled = true

[node name="MeshInstance" type="MeshInstance3D" parent="StaticBody/CollisionShape"]
mesh = SubResource( "2" )
mesh = SubResource("2")

[node name="StaticBody" type="StaticBody3D" parent="StaticBody/CollisionShape/MeshInstance"]

[node name="CollisionShape" type="CollisionShape3D" parent="StaticBody/CollisionShape/MeshInstance/StaticBody"]
shape = SubResource( "3" )
shape = SubResource("3")

[node name="ServerCamera" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.866025, 0.5, 0, -0.5, 0.866025, 0, 10.6518, 37.3083)
current = true

[node name="Menu" type="Control" parent="."]
layout_mode = 3
anchors_preset = 10
anchor_right = 1.0
grow_horizontal = 2

[node name="VBoxContainer" type="VBoxContainer" parent="Menu"]
layout_mode = 0
anchor_left = 0.5
anchor_right = 0.5

[node name="ServerButton" type="Button" parent="Menu/VBoxContainer"]
offset_right = 107.0
offset_bottom = 31.0
layout_mode = 2
text = "Start Server"

[node name="ClientButton" type="Button" parent="Menu/VBoxContainer"]
offset_top = 35.0
offset_right = 107.0
offset_bottom = 66.0
layout_mode = 2
text = "Client Server"

[node name="SyncMesh" parent="." instance=ExtResource( "3" )]
[node name="SyncMesh" parent="." instance=ExtResource("3")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6.12977, 0.11825, 0.354554)

[node name="SyncMesh2" parent="." instance=ExtResource( "3" )]
[node name="SyncMesh2" parent="." instance=ExtResource("3")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6.21811, 0.11825, 0.46023)

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( "4" )
environment = SubResource("4")

[node name="StaticBody2" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 6)

[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody2"]
mesh = SubResource( "5" )
mesh = SubResource("5")

[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody2"]
shape = SubResource( "6" )
shape = SubResource("6")

[node name="StaticBody3" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 11)

[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody3"]
mesh = SubResource( "5" )
mesh = SubResource("5")

[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3"]
shape = SubResource( "6" )
shape = SubResource("6")

[node name="StaticBody4" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7, 0, 11)

[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody4"]
mesh = SubResource( "5" )
mesh = SubResource("5")

[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody4"]
shape = SubResource( "6" )
shape = SubResource("6")

[node name="StaticBody6" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -8.57699)

[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody6"]
mesh = SubResource( "5" )
mesh = SubResource("5")

[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody6"]
shape = SubResource( "6" )
shape = SubResource("6")

[node name="StaticBody5" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, 11)

[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody5"]
mesh = SubResource( "5" )
mesh = SubResource("5")

[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody5"]
shape = SubResource( "6" )
shape = SubResource("6")

[connection signal="button_up" from="Menu/VBoxContainer/ServerButton" to="." method="_start_server"]
[connection signal="button_up" from="Menu/VBoxContainer/ClientButton" to="." method="_start_client"]