Changing up authority
This commit is contained in:
parent
999a88c402
commit
b1b6cdd712
@ -35,15 +35,18 @@ func _ready():
|
||||
player_detection_area.body_exited.connect(_on_player_exited)
|
||||
|
||||
func _process(delta: float):
|
||||
if NetworkManager.is_host:
|
||||
if ship_is_piloted and piloting_player.steam_id == NetworkManager.steam_id:
|
||||
handle_input(delta)
|
||||
send_network_update()
|
||||
elif ship_is_piloted and piloting_player.steam_id == NetworkManager.steam_id:
|
||||
if ship_is_piloted:
|
||||
if piloting_player.steam_id == NetworkManager.steam_id:
|
||||
# This player is piloting
|
||||
handle_input(delta)
|
||||
send_network_update()
|
||||
else:
|
||||
# Another player is piloting, interpolate
|
||||
interpolate_position_and_rotation(delta)
|
||||
else:
|
||||
# No one is piloting, just interpolate
|
||||
interpolate_position_and_rotation(delta)
|
||||
|
||||
|
||||
func handle_input(_delta: float):
|
||||
var forward_input = 0.0
|
||||
@ -122,14 +125,15 @@ func _on_player_exited(body):
|
||||
|
||||
|
||||
func send_network_update():
|
||||
if NetworkManager.is_host:
|
||||
if ship_is_piloted and piloting_player.steam_id == NetworkManager.steam_id or !ship_is_piloted:
|
||||
if NetworkManager.is_host and ship_is_piloted and piloting_player.steam_id == NetworkManager.steam_id:
|
||||
# Host is piloting, synchronize with clients
|
||||
if global_position.distance_to(previous_position) > 0.1 or global_transform.basis.get_rotation_quaternion().dot(previous_rotation) < 0.99:
|
||||
NetworkManager.sync_property_to_all_except_host(network_uuid, "global_position", global_position)
|
||||
NetworkManager.sync_property_to_all_except_host(network_uuid, "global_rotation", global_transform.basis.get_rotation_quaternion())
|
||||
previous_position = global_position
|
||||
previous_rotation = global_transform.basis.get_rotation_quaternion()
|
||||
elif ship_is_piloted and piloting_player.steam_id == NetworkManager.steam_id:
|
||||
elif !NetworkManager.is_host and ship_is_piloted and piloting_player.steam_id == NetworkManager.steam_id:
|
||||
# Client is piloting, send updates to the host
|
||||
if global_position.distance_to(previous_position) > 0.1 or global_transform.basis.get_rotation_quaternion().dot(previous_rotation) < 0.99:
|
||||
NetworkManager.sync_property_to_all(network_uuid, "global_position", global_position)
|
||||
NetworkManager.sync_property_to_all(network_uuid, "global_rotation", global_transform.basis.get_rotation_quaternion())
|
||||
@ -137,6 +141,7 @@ func send_network_update():
|
||||
previous_rotation = global_transform.basis.get_rotation_quaternion()
|
||||
|
||||
|
||||
|
||||
func receive_global_position_update(value: Vector3):
|
||||
target_position = value
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user