i’m hosting on Heroic Cloud and following this: Client Relayed Multiplayer - Heroic Labs Documentation
created a simple ping calculation, and the latency is around 500ms (tested with 3 different clients in 3 different locations)
how can i improve it?
how i calculate the ping in godot:
var ping_history: Array[int] = []
var ping: int
func _ready() -> void:
Net.received_match_state.connect(_on_match_state)
func _on_match_state(state : NakamaRTAPI.MatchData) -> void:
if not state.op_code == Net.OpCodes.PING_PONG:
return
if lobby_data.authority == null:
return
var data: Dictionary = JSON.parse_string(state.data)
if is_match_authority() and data.has("time"):
Net.socket.send_match_state_async(Net.connected_match.match_id, OpCodes.PING_PONG, JSON.stringify({"time": data["time"]}), [state.presence])
return
ping_history.push_front(Time.get_ticks_msec() - int(data["time"]))
if ping_history.size() > 10:
ping_history.pop_back()
var total: int = 0
for p in ping_history:
total += p
ping = roundi(float(total) / ping_history.size())
func _on_ping_request_timer_timeout() -> void:
if not is_instance_valid(connected_match):
return
if is_match_authority():
return
send_match_state(OpCodes.PING_PONG, {"time": Time.get_ticks_msec()})