fix: FPS character controller review fixes
- Camera: Make view bob additive to crouch eye height (was overwriting position.y) - Camera: Sustain sprint FOV kick while sprinting (was recovering immediately) - Camera: Remove unused _was_sprinting variable - Controller: Use just_pressed for jump (was sending every frame while held) - Controller: Direct input dict assignment instead of merge() to avoid alloc - Controller: Add clearer comments on server-authoritative readback mode
This commit is contained in:
@@ -70,12 +70,12 @@ var _weapon_rest: Transform3D
|
||||
var _base_fov: float = 75.0
|
||||
var _current_fov_offset: float = 0.0
|
||||
|
||||
## Sway state.
|
||||
## Sway state (used as both current value and interpolation target).
|
||||
var _sway_current: Vector2 = Vector2.ZERO
|
||||
var _sway_target: Vector2 = Vector2.ZERO
|
||||
|
||||
## Sprint state cache (detect transition for FOV kick).
|
||||
var _was_sprinting: bool = false
|
||||
## Base eye Y set by parent controller's crouch logic (for additive bob).
|
||||
var _base_eye_y: float = 0.0
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Lifecycle
|
||||
@@ -100,6 +100,10 @@ func _process(delta: float) -> void:
|
||||
if _controller == null:
|
||||
return
|
||||
|
||||
# Capture the eye height set by parent controller's crouch logic
|
||||
# before we apply view bob offsets (which must be additive).
|
||||
_base_eye_y = position.y
|
||||
|
||||
# FOV management
|
||||
_update_fov(delta)
|
||||
|
||||
@@ -119,16 +123,15 @@ func _process(delta: float) -> void:
|
||||
func _update_fov(delta: float) -> void:
|
||||
var target_offset: float = 0.0
|
||||
|
||||
# Sprint FOV kick
|
||||
if _controller.is_sprinting() and not _was_sprinting:
|
||||
# Sprint FOV kick — sustained while sprinting (not just on transition)
|
||||
if _controller.is_sprinting():
|
||||
target_offset = sprint_fov_kick
|
||||
|
||||
# Shoot FOV kick is triggered externally via trigger_shoot_fov()
|
||||
# and decays toward the sprint/walk target naturally via move_toward.
|
||||
_current_fov_offset = move_toward(_current_fov_offset, target_offset, fov_recovery_speed * delta)
|
||||
fov = _base_fov + _current_fov_offset
|
||||
|
||||
_was_sprinting = _controller.is_sprinting()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# View bobbing
|
||||
@@ -157,7 +160,9 @@ func _update_bob(delta: float) -> void:
|
||||
|
||||
# Apply bob to camera position (relative to parent's eye offset)
|
||||
position.x = _bob_offset.x
|
||||
position.y = _bob_offset.y
|
||||
# Bob is additive on Y so it does NOT overwrite the crouch eye height
|
||||
# set by the parent FPSCharacterController._update_crouch().
|
||||
position.y = _base_eye_y + _bob_offset.y
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user