Skip to content
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

Send player position updates at a lower rate #206

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/assets/main/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func _enter_tree() -> void:
get_tree().connect("network_peer_disconnected", self, "_player_disconnected")

# Keep the clients' player positions updated
func _physics_process(_delta: float) -> void:
func _on_NetworkUpdateTimer_timeout() -> void:
if get_tree().is_network_server():
var positions_dict = {}
for id in players.keys():
Expand Down
6 changes: 6 additions & 0 deletions src/assets/main/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ color = Color( 0.188235, 0.164706, 0.164706, 1 )

[node name="maps" type="YSort" parent="."]
script = ExtResource( 2 )

[node name="NetworkUpdateTimer" type="Timer" parent="."]
process_mode = 0
wait_time = 0.1
autostart = true
[connection signal="spawn" from="maps" to="." method="_on_maps_spawn"]
[connection signal="timeout" from="NetworkUpdateTimer" to="." method="_on_NetworkUpdateTimer_timeout"]
6 changes: 5 additions & 1 deletion src/assets/player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,12 @@ func _on_positions_updated(new_last_received_input: int):
run_physics(i[0])

func move_to(new_pos, new_movement):
position = new_pos
movement = new_movement
if main_player:
position = new_pos
else:
$Tween.interpolate_property(self, "position", null, new_pos, 0.1)
$Tween.start()

func get_is_alive() -> bool:
return not death_handler.is_dead
2 changes: 2 additions & 0 deletions src/assets/player/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,7 @@ script = ExtResource( 3 )
__meta__ = {
"_editor_description_": "Handles being killed by infiltrators."
}

[node name="Tween" type="Tween" parent="."]
[connection signal="body_entered" from="interactarea" to="interactarea" method="_on_interactarea_body_entered"]
[connection signal="body_exited" from="interactarea" to="interactarea" method="_on_interactarea_body_exited"]