fix: recover players from shallow freshwater

This commit is contained in:
Alexander Sellite 2026-08-23 00:50:45 -04:00
parent d2ee4a515e
commit 8dbeb06e73
6 changed files with 65 additions and 7 deletions

View file

@ -9,6 +9,11 @@ enum SurfaceHeightMode {
PARENT_GLOBAL_Y,
}
enum EntryHeightReference {
BODY_CENTER,
PLAYER_ORIGIN,
}
@export_group("Surface")
@export var surface_height_mode: SurfaceHeightMode = SurfaceHeightMode.EXPLICIT:
set(value):
@ -18,7 +23,11 @@ enum SurfaceHeightMode {
## Legacy explicit height used when Surface Height Mode is Explicit.
@export var surface_height: float = 0.2
@export_group("Recovery Trigger")
## Recovery begins when the player's body center reaches this depth.
## Point on the player used to measure entry depth below the water surface.
@export var entry_height_reference: EntryHeightReference = (
EntryHeightReference.BODY_CENTER
)
## Recovery begins when the selected reference reaches this depth.
@export_range(0.0, 2.0, 0.05) var entry_depth_threshold: float = 0.35
var _tracked_players: Array[Player] = []
@ -42,10 +51,10 @@ func _physics_process(_delta: float) -> void:
var player_key: StringName = StringName(str(player.get_instance_id()))
if _triggered_players.has(player_key):
continue
if (
player.get_body_center_position().y
<= active_surface_height - entry_depth_threshold
):
var entry_height := player.get_body_center_position().y
if entry_height_reference == EntryHeightReference.PLAYER_ORIGIN:
entry_height = player.global_position.y
if entry_height <= active_surface_height - entry_depth_threshold:
_triggered_players[player_key] = true
recovery_requested.emit(player, active_surface_height)