Messing with interpolation
This commit is contained in:
parent
b1b6cdd712
commit
2e5428ae91
@ -74,9 +74,10 @@ func handle_input(_delta: float):
|
||||
# Apply torque for turning
|
||||
if turn_input != 0:
|
||||
var torque = Vector3.UP * turn_input * base_turn_speed
|
||||
apply_torque(torque)
|
||||
apply_torque(torque.clamp_length(max_turn_speed))
|
||||
|
||||
# Apply force for forward and backward movement
|
||||
|
||||
# Apply force for forward and backward movement
|
||||
if forward_input != 0:
|
||||
var forward_direction = -global_transform.basis.z.normalized()
|
||||
var forward_force = forward_direction * forward_input * move_speed
|
||||
@ -89,11 +90,13 @@ func handle_input(_delta: float):
|
||||
|
||||
|
||||
func interpolate_position_and_rotation(delta: float):
|
||||
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_position = lerp(global_position, target_position, min(acceleration * delta, 1.0))
|
||||
|
||||
var current_rotation = global_transform.basis.get_rotation_quaternion().normalized()
|
||||
var interpolated_rotation = current_rotation.slerp(target_rotation, min(acceleration * delta, 1.0))
|
||||
global_transform.basis = Basis(interpolated_rotation)
|
||||
|
||||
|
||||
func set_piloting_player(player: Player):
|
||||
piloting_player = player
|
||||
ship_is_piloted = piloting_player != null
|
||||
@ -127,21 +130,23 @@ func _on_player_exited(body):
|
||||
func send_network_update():
|
||||
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:
|
||||
if global_position.distance_to(previous_position) > 0.1 or global_transform.basis.get_rotation_quaternion().dot(previous_rotation) < 0.995:
|
||||
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())
|
||||
if global_position.distance_to(previous_position) > 0.1 or global_transform.basis.get_rotation_quaternion().dot(previous_rotation) < 0.995:
|
||||
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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func receive_global_position_update(value: Vector3):
|
||||
target_position = value
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user