Changing up authority
This commit is contained in:
parent
999a88c402
commit
b1b6cdd712
@ -35,16 +35,19 @@ 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:
|
||||
if ship_is_piloted:
|
||||
if piloting_player.steam_id == NetworkManager.steam_id:
|
||||
# This player is piloting
|
||||
handle_input(delta)
|
||||
send_network_update()
|
||||
elif ship_is_piloted and piloting_player.steam_id == NetworkManager.steam_id:
|
||||
handle_input(delta)
|
||||
send_network_update()
|
||||
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
|
||||
var turn_input = 0.0
|
||||
@ -86,7 +89,7 @@ func handle_input(_delta: float):
|
||||
|
||||
|
||||
func interpolate_position_and_rotation(delta: float):
|
||||
global_position = lerp(global_position,target_position, acceleration * delta)
|
||||
global_position = lerp(global_position, target_position, acceleration * delta)
|
||||
var current_rotation = global_transform.basis.get_rotation_quaternion()
|
||||
var interpolated_rotation = current_rotation.slerp(target_rotation, acceleration * delta)
|
||||
global_transform.basis = Basis(interpolated_rotation)
|
||||
@ -122,19 +125,21 @@ 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 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:
|
||||
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 !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())
|
||||
previous_position = global_position
|
||||
previous_rotation = global_transform.basis.get_rotation_quaternion()
|
||||
|
||||
|
||||
|
||||
func receive_global_position_update(value: Vector3):
|
||||
|
Loading…
Reference in New Issue
Block a user