Potential fix for ship sync

This commit is contained in:
Chris Bell 2024-12-18 22:44:08 -06:00
parent cf3beff3e5
commit 52ed547ab2

View File

@ -46,44 +46,42 @@ func _physics_process(_delta):
if ship_is_piloted: if ship_is_piloted:
var turn_speed = base_turn_speed / max(mass, 1) var turn_speed = base_turn_speed / max(mass, 1)
var lift_speed = base_lift_speed / max(mass, 1) var lift_speed = base_lift_speed / max(mass, 1)
if Input.is_action_pressed("move_left"): if Input.is_action_pressed("move_left"):
angular_velocity.y += turn_speed angular_velocity.y += turn_speed
elif Input.is_action_pressed("move_right"): elif Input.is_action_pressed("move_right"):
angular_velocity.y -= turn_speed angular_velocity.y -= turn_speed
else: else:
global_rotation.z = lerpf(global_rotation.z, 0, 0.8) global_rotation.z = lerpf(global_rotation.z, 0, 0.8)
if Input.is_action_pressed("jump"): if Input.is_action_pressed("jump"):
linear_velocity.y += lift_speed linear_velocity.y += lift_speed
elif Input.is_action_pressed("crouch"): elif Input.is_action_pressed("crouch"):
linear_velocity.y -= lift_speed linear_velocity.y -= lift_speed
var target_velocity = Vector3.ZERO var target_velocity = Vector3.ZERO
if Input.is_action_pressed("move_forwards"): if Input.is_action_pressed("move_forwards"):
target_velocity = -transform.basis.z * top_speed target_velocity = -transform.basis.z * top_speed
elif Input.is_action_pressed("move_backwards"): elif Input.is_action_pressed("move_backwards"):
target_velocity = transform.basis.z * top_speed target_velocity = transform.basis.z * top_speed
var current_acceleration = (target_velocity - linear_velocity) * acceleration var current_acceleration = (target_velocity - linear_velocity) * acceleration
apply_central_force(current_acceleration * mass) apply_central_force(current_acceleration * mass)
if linear_velocity.length() > top_speed: if linear_velocity.length() > top_speed:
linear_velocity = linear_velocity.normalized() * top_speed linear_velocity = linear_velocity.normalized() * top_speed
angular_velocity.y = clamp(angular_velocity.y, -max_turn_speed, max_turn_speed) angular_velocity.y = clamp(angular_velocity.y, -max_turn_speed, max_turn_speed)
#if NetworkManager.is_host: global_rotation.x = lerpf(global_rotation.x, 0, 0.1)
global_rotation.z = lerpf(global_rotation.z, 0, 0.1)
if piloting_player == null or !piloting_player.is_network_authority:
if old_global_position_cache != global_position: if old_global_position_cache != global_position:
NetworkManager.sync_property(uuid, "global_position", global_position) NetworkManager.sync_property(uuid, "global_position", global_position)
old_global_position_cache = global_position old_global_position_cache = global_position
if old_global_rotation_cache != global_rotation: if old_global_rotation_cache != global_rotation:
NetworkManager.sync_property(uuid, "global_rotation", global_rotation) NetworkManager.sync_property(uuid, "global_rotation", global_rotation)
old_global_rotation_cache = global_rotation old_global_rotation_cache = global_rotation
# Self level slowly if host
global_rotation.x = lerpf(global_rotation.x, 0, 0.1)
global_rotation.z = lerpf(global_rotation.z, 0, 0.1)
func _on_area_3d_body_entered(body: Node3D) -> void: func _on_area_3d_body_entered(body: Node3D) -> void: