Move to physics based mouse input and try bugfix for basis reset
This commit is contained in:
@ -141,7 +141,7 @@ func _orient_pawn(delta: float):
|
||||
|
||||
# 2. Smoothly Interpolate Towards Target Basis
|
||||
var current_basis = pawn.global_basis
|
||||
var new_basis = current_basis.slerp(target_basis, delta * orientation_speed).orthonormalized()
|
||||
var new_basis = current_basis.slerp(target_basis, delta * orientation_speed).get_rotation_quaternion()
|
||||
|
||||
# Store the body's yaw *before* applying the new basis
|
||||
var _old_body_yaw = current_basis.get_euler().y
|
||||
|
||||
@ -6,6 +6,7 @@ class_name PlayerController3D
|
||||
|
||||
# --- Mouse Sensitivity ---
|
||||
@export var mouse_sensitivity: float = 0.002 # Radians per pixel motion
|
||||
var _mouse_motion_input: Vector2 = Vector2.ZERO
|
||||
|
||||
class KeyInput:
|
||||
var pressed: bool = false
|
||||
@ -24,19 +25,23 @@ func _unhandled_input(event: InputEvent):
|
||||
|
||||
# Handle mouse motion input directly here
|
||||
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
# Calculate yaw and pitch based on mouse movement
|
||||
var yaw_input = event.relative.x
|
||||
var pitch_input = -event.relative.y
|
||||
_mouse_motion_input += Vector2(event.relative.x, -event.relative.y)
|
||||
|
||||
var sensitivity_modified_mouse_input = Vector2(yaw_input, pitch_input) * mouse_sensitivity
|
||||
|
||||
# Send rotation input via RPC immediately
|
||||
server_process_rotation_input.rpc_id(multiplayer.get_unique_id(), sensitivity_modified_mouse_input)
|
||||
|
||||
func _physics_process(_delta):
|
||||
if not is_multiplayer_authority() or not is_instance_valid(possessed_pawn):
|
||||
return
|
||||
|
||||
if _mouse_motion_input != Vector2.ZERO:
|
||||
# Calculate yaw and pitch based on mouse movement
|
||||
var sensitivity_modified_mouse_input = Vector2(_mouse_motion_input.x, _mouse_motion_input.y) * mouse_sensitivity
|
||||
|
||||
# Send rotation input via RPC immediately
|
||||
server_process_rotation_input.rpc_id(multiplayer.get_unique_id(), sensitivity_modified_mouse_input)
|
||||
|
||||
# Reset the buffer
|
||||
_mouse_motion_input = Vector2.ZERO
|
||||
|
||||
|
||||
var move_vec = Input.get_vector("move_left_3d", "move_right_3d", "move_backward_3d", "move_forward_3d")
|
||||
var roll_input = Input.get_action_strength("roll_right_3d") - Input.get_action_strength("roll_left_3d")
|
||||
var vertical_input = Input.get_action_strength("move_up_3d") - Input.get_action_strength("move_down_3d")
|
||||
|
||||
Reference in New Issue
Block a user