Skip to content

Commit 3bab298

Browse files
committed
fix: hit area detection when wandering Doro faces right (flip_h=true)
When the wandering Doro turned to face right, clicks on body parts (face, legs, etc.) would not trigger interactions. The model still animated, but `recalc_mouse_position` returned coordinates far outside the canvas so no hit-area test ever matched. Root cause: in `model.gd`, `flip_h = true` sets the Node2D scale to `(-0.3, 0.3)`. That negative-x scale flows through Godot's coordinate transforms automatically: 1. `model.to_local(event.position)` already divides by the negative scale, mirroring x once. 2. `position * model.get_scale()` then multiplies by the same negative scale, mirroring x back to viewport space. So at line 27 the position is *already* in unflipped viewport coords. The extra `if model.flip_h: position.x = -position.x` on lines 28-29 was a spurious third flip, performed in viewport coords *before* the center offset and canvas-scale division. The later flip on lines 36-37 is the correct one: it mirrors around the canvas origin (after the viewport-center subtraction), which is what hit-area detection expects when the model is rendered mirrored. With both flips active, a click at viewport (320, 320) on a flipped model came out as (1024, 0) in canvas coords instead of the correct (0, 0) — one full canvas-width off, so no hit area ever triggered. Fix: drop the redundant first flip; keep the canvas-space flip at the end of the function. The unflipped (flip_h=false) code path is unchanged — same diff outputs for every input I traced through. Testing scope (please regression-check before merging): - Bug analysis is platform-independent — depends only on Godot's Node2D transform semantics and on `model.gd` setting a negative x-scale for flip_h. Both apply on Windows the same way they apply on Linux. - Verified informally by manual click-testing on a downstream RHEL 9.7 / X11 build (via WSL 2 + WSLg). Walked the wandering Doro right-ward and confirmed the SmileEyeClosed expression triggers on the face hit area from both facing directions. - NOT re-tested on the upstream Windows build. A regression check there before merging would be appreciated, particularly on the flip_h=false path to confirm nothing changes for Windows users whose pets face left.
1 parent c2050bd commit 3bab298

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

scripts/gd/interact/hit_area_handler.gd

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ func _process(delta):
2525

2626
func recalc_mouse_position(position):
2727
position = position * model.get_scale()
28-
if model.flip_h:
29-
position.x = -position.x
30-
28+
3129
if canvas_info.is_empty() != true:
3230
var vct_viewport_size = Vector2(root.get_viewport_rect().size)
3331
var scale: float = vct_viewport_size.y / max(canvas_info.size_in_pixels.x, canvas_info.size_in_pixels.y)
3432
position -= vct_viewport_size / 2.0
3533
position /= Vector2(scale, scale)
3634
if model.flip_h:
3735
position.x = -position.x
38-
36+
3937
return position
4038

4139
func _on_hit_area_entered(model: GDCubismUserModel, id: String) -> void:

0 commit comments

Comments
 (0)