move to apply_input_velocity on the subject
This commit is contained in:
+21
-8
@@ -33,7 +33,7 @@ extends CharacterBody3D
|
||||
@onready var _camera_pivot: Node3D = %CameraPivot
|
||||
@onready var _camera_platform: Node3D = %CameraPlatform
|
||||
@onready var _camera: Node3D = %Camera
|
||||
@onready var skin: Node3D = %Skin
|
||||
@onready var rotation_base: Node3D = %RotationBase
|
||||
|
||||
var camera_input_direction := Vector2.ZERO
|
||||
var last_direction := Vector3.FORWARD
|
||||
@@ -46,9 +46,9 @@ func _ready() -> void:
|
||||
if multiplayer.is_server(): return
|
||||
|
||||
if multiplayer.get_unique_id() == player_id:
|
||||
%Camera.make_current()
|
||||
_camera.make_current()
|
||||
else:
|
||||
%Camera.clear_current(false)
|
||||
_camera.clear_current(false)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if multiplayer.get_unique_id() != player_id: return
|
||||
@@ -86,21 +86,34 @@ func _physics_process(delta: float) -> void:
|
||||
if not multiplayer.is_server():
|
||||
if multiplayer.get_unique_id() == player_id and client_prediction:
|
||||
predicted_position = position
|
||||
predicted_rotation = skin.global_rotation
|
||||
predicted_rotation = rotation_base.global_rotation
|
||||
|
||||
if multiplayer.get_unique_id() != player_id or not client_prediction:
|
||||
if client_smoothing:
|
||||
position = lerp(position, server_position, client_smoothing_speed * delta)
|
||||
skin.global_rotation.y = lerp_angle(skin.global_rotation.y, server_rotation.y, client_smoothing_rotation_speed * delta)
|
||||
rotation_base.global_rotation.x = server_rotation.x
|
||||
rotation_base.global_rotation.y = lerp_angle(rotation_base.global_rotation.y, server_rotation.y, client_smoothing_rotation_speed * delta)
|
||||
rotation_base.global_rotation.z = server_rotation.z
|
||||
else:
|
||||
position = server_position
|
||||
skin.global_rotation.y = server_rotation.y
|
||||
|
||||
rotation_base.global_rotation = server_rotation
|
||||
#
|
||||
if multiplayer.is_server():
|
||||
server_position = position
|
||||
server_rotation = skin.global_rotation
|
||||
server_rotation = rotation_base.global_rotation
|
||||
|
||||
func _on_sync_delta_synchronized() -> void:
|
||||
if client_prediction and server_position.distance_to(predicted_position) > client_prediction_tolerance:
|
||||
print("%v VS %v" % [server_position, predicted_position])
|
||||
position = server_position
|
||||
|
||||
|
||||
func apply_input_velocity(delta: float, input_direction: Vector2, speed: float, acceleration: float) -> void:
|
||||
var target_velocity = Vector3(input_direction.x * speed, velocity.y, input_direction.y * speed)
|
||||
velocity = velocity.move_toward(target_velocity, acceleration * delta) + Main.gravity_velocity
|
||||
move_and_slide()
|
||||
|
||||
if input_direction.length() >= 0.1:
|
||||
last_direction = Vector3(input_direction.x, 0, input_direction.y)
|
||||
var target_angle := Vector3.FORWARD.signed_angle_to(last_direction, Vector3.UP)
|
||||
rotation_base.global_rotation.y = lerp_angle(rotation_base.rotation.y, target_angle, rotation_speed * delta)
|
||||
|
||||
Reference in New Issue
Block a user