Skip to content

Commit

Permalink
Send player position updates at a lower rate
Browse files Browse the repository at this point in the history
  • Loading branch information
vainiovano committed Nov 21, 2020
1 parent 607ed10 commit 1221273
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/assets/main/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func _enter_tree():
get_tree().connect("network_peer_disconnected", self, "_player_disconnected")

# Keep the clients' player positions updated
func _physics_process(_delta):
func _on_NetworkUpdateTimer_timeout():
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 @@ -127,5 +127,9 @@ 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()
2 changes: 2 additions & 0 deletions src/assets/player/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,7 @@ align = 1
__meta__ = {
"_edit_use_anchors_": false
}

[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"]

0 comments on commit 1221273

Please sign in to comment.