decouple camera from runner position
This commit is contained in:
@@ -3,6 +3,8 @@ extends MultiplayerSynchronizer
|
||||
@export var direction: Vector2 = Vector2.ZERO
|
||||
@export var walking: bool = false
|
||||
|
||||
@onready var _camera_pivot: Node3D = %CameraPivot
|
||||
|
||||
func _ready() -> void:
|
||||
if multiplayer.is_server() or get_multiplayer_authority() != multiplayer.get_unique_id():
|
||||
set_process(false)
|
||||
@@ -11,6 +13,6 @@ func _ready() -> void:
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
var directional_input := Input.get_vector("move_right", "move_left", "move_forward", "move_back")
|
||||
var camera_adjusted: Vector3 = (directional_input.x * %CameraTarget.global_basis.z) + (directional_input.y * %CameraTarget.global_basis.x)
|
||||
var camera_adjusted: Vector3 = (directional_input.x * _camera_pivot.global_basis.z) + (directional_input.y * _camera_pivot.global_basis.x)
|
||||
direction = Vector2(camera_adjusted.x, camera_adjusted.z).rotated(PI / 2.0).normalized()
|
||||
walking = Input.is_action_pressed("walk")
|
||||
|
||||
+13
-12
@@ -9,7 +9,7 @@ extends CharacterBody3D
|
||||
|
||||
@export_group("Camera")
|
||||
@export_range(0.0, 1.0) var mouse_sensitivity := 0.2
|
||||
@export var camera_follow_speed := 10.0
|
||||
@export var camera_follow_speed := 20.0
|
||||
@export var smooth_camera := false
|
||||
|
||||
@export_group("Movement")
|
||||
@@ -21,11 +21,11 @@ extends CharacterBody3D
|
||||
|
||||
@export_group("Client Tweening")
|
||||
@export var client_smoothing := false
|
||||
@export var client_smoothing_speed := 5.0
|
||||
@export var client_smoothing_rotation_speed := 10.0
|
||||
@export var client_smoothing_speed := 10.0
|
||||
@export var client_smoothing_rotation_speed := 25.0
|
||||
|
||||
@onready var _camera_pivot: Node3D = %CameraPivot
|
||||
@onready var _camera_target: Node3D = %CameraTarget
|
||||
@onready var _camera_platform: Node3D = %CameraPlatform
|
||||
@onready var _camera: Node3D = %Camera
|
||||
@onready var skin: Node3D = %Skin
|
||||
|
||||
@@ -59,6 +59,15 @@ func _input(event: InputEvent) -> void:
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
camera_input_direction += event.screen_relative * mouse_sensitivity
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if multiplayer.get_unique_id() == player_id:
|
||||
_camera_platform.global_rotation = _camera_pivot.global_rotation
|
||||
|
||||
if smooth_camera:
|
||||
_camera_platform.global_position = lerp(_camera_platform.global_position, _camera_pivot.global_position, camera_follow_speed * delta)
|
||||
else:
|
||||
_camera_platform.global_position = _camera_pivot.global_position
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
state_machine.process_physics(delta)
|
||||
if multiplayer.get_unique_id() == player_id:
|
||||
@@ -67,15 +76,7 @@ func _physics_process(delta: float) -> void:
|
||||
-PI / 3.0,
|
||||
PI / 6.0,
|
||||
)
|
||||
|
||||
_camera_pivot.rotation.y -= camera_input_direction.x * delta
|
||||
_camera.global_rotation = _camera_pivot.global_rotation
|
||||
|
||||
if smooth_camera:
|
||||
_camera.global_position = lerp(_camera.global_position, _camera_target.global_position, camera_follow_speed * delta)
|
||||
else:
|
||||
_camera.global_position = _camera_target.global_position
|
||||
|
||||
camera_input_direction = Vector2.ZERO
|
||||
|
||||
if not multiplayer.is_server():
|
||||
|
||||
Reference in New Issue
Block a user