From 2ab0025b8ca962625b0f01d815343637dec72580 Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 16 Mar 2026 16:51:46 -0400 Subject: [PATCH] Fix stalagmite positioning: add_child before AABB/fit calls MeshInstance3D.get_aabb() returns a zero AABB when the node is not yet in the scene tree, so the previous code's _fit_model_to_tile call was a no-op (early return on zero footprint) and scaled_h was always 0. Fix: add_child the stalagmite to the tile body FIRST (matching the same order used by _try_load_tile_model for tile top models), then call _fit_model_to_tile, then read the now-valid AABB to compute scaled_h and apply the correct downward shift so the wide base lands flush with the tile underside. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../origin-client/scenes/game/game_screen.gd | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index edce54e..e8905c9 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -532,27 +532,24 @@ func _try_load_tile_bottom(body_ref: Variant, url: String) -> void: return if bottom_node == null: return - # The body centre is at world Y = tile_h/2. - # The tile underside is at body-local Y = -tile_h/2 (= world Y = 0). - # - # The stalagmite models are spike-at-bottom: the AABB minimum (Y=0 after - # _fit_model_to_tile) is the narrow spike tip; the AABB maximum is the - # wide flat base. No flip is needed — we just need to push the model down - # so the AABB top (wide base) lands exactly at the tile underside. - # - # After _fit_model_to_tile: - # AABB bottom (spike) → body-local Y = 0 - # AABB top (base) → body-local Y = scaled_h - # We want: - # AABB top (base) → body-local Y = -tile_h/2 - # So shift by -(tile_h/2 + scaled_h): - var tile_h : float = float(b.get_meta("tile_height", 1.0)) - var btm_aabb := _model_local_aabb(bottom_node) - var btm_fp : float = max(btm_aabb.size.x, btm_aabb.size.z) - var scaled_h : float = btm_aabb.size.y * (0.98 / btm_fp) if btm_fp > 0.0 else 0.0 - _fit_model_to_tile(bottom_node, 0.98) - bottom_node.position.y -= tile_h * 0.5 + scaled_h + # IMPORTANT: add_child BEFORE _fit_model_to_tile / _model_local_aabb. + # MeshInstance3D.get_aabb() returns a zero AABB until the node is in the + # scene tree, so both functions must run after the node is parented. + var tile_h : float = float(b.get_meta("tile_height", 1.0)) b.add_child(bottom_node) + + # Scale to fit the tile footprint. Now that the node is in the tree, + # the internal _model_local_aabb call returns a valid AABB. + _fit_model_to_tile(bottom_node, 0.98) + + # After fitting: AABB bottom (spike tip) is at body-local Y=0, + # AABB top (wide base) is at body-local Y = scaled_h. + # We want the wide base flush with the tile underside (body-local Y=-tile_h/2). + # Shift = -(tile_h/2 + scaled_h). + var btm_aabb := _model_local_aabb(bottom_node) + if btm_aabb.size != Vector3.ZERO: + var scaled_h := bottom_node.scale.y * btm_aabb.size.y + bottom_node.position.y -= tile_h * 0.5 + scaled_h )