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

@ -393,6 +393,10 @@ func _configure_fresh_water(records: Array[Dictionary]) -> void:
body.visual_surface_enabled = false
body.water_material = _fresh_water_material()
body.water_type = WaterType.Type.FRESH_WATER
body.recovery_entry_height_reference = (
PlayerWaterTrigger.EntryHeightReference.PLAYER_ORIGIN
)
body.recovery_entry_depth_threshold = 0.1
body.fish_pool = _fresh_water_pool(tags)
body.location_tags = _fresh_water_location_tags(tags)
body.selection_priority = 10

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)

View file

@ -161,6 +161,8 @@ water_material = ExtResource("19_fresh_water")
fish_pool = ExtResource("12_pond_pool")
location_tags = Array[StringName]([&"starter_pond", &"pond"])
selection_priority = 1
recovery_entry_height_reference = 1
recovery_entry_depth_threshold = 0.1
[node name="VisualWater" type="MeshInstance3D" parent="WaterBodies/Pond" unique_id=1034265960]
material_override = ExtResource("19_fresh_water")

View file

@ -69,6 +69,17 @@ var fishing_depth: float = 4.0:
set(value):
manage_recovery_coverage = value
_sync_owned_nodes()
@export var recovery_entry_height_reference: PlayerWaterTrigger.EntryHeightReference = (
PlayerWaterTrigger.EntryHeightReference.BODY_CENTER
):
set(value):
recovery_entry_height_reference = value
_sync_owned_nodes()
@export_range(0.0, 2.0, 0.05)
var recovery_entry_depth_threshold: float = 0.35:
set(value):
recovery_entry_depth_threshold = clampf(value, 0.0, 2.0)
_sync_owned_nodes()
@export_range(0.1, 20.0, 0.1, "or_greater", "suffix:m")
var recovery_depth: float = 4.8:
set(value):
@ -150,12 +161,18 @@ func _sync_owned_nodes() -> void:
if manage_recovery_coverage:
var recovery_region := (
get_node_or_null(recovery_region_path) as Area3D
get_node_or_null(recovery_region_path) as PlayerWaterTrigger
)
var recovery_shape_node := (
get_node_or_null(recovery_shape_path) as CollisionShape3D
)
if recovery_region != null and recovery_shape_node != null:
recovery_region.entry_height_reference = (
recovery_entry_height_reference
)
recovery_region.entry_depth_threshold = (
recovery_entry_depth_threshold
)
if uses_polygon and _sync_polygon_collision_shapes(
recovery_region,
recovery_shape_node,