Skip to content

fix: Crystal ball example dragging no longer causes camera to jump#3925

Merged
spydon merged 5 commits into
mainfrom
fix/crystal-ball-drag-jump
May 18, 2026
Merged

fix: Crystal ball example dragging no longer causes camera to jump#3925
spydon merged 5 commits into
mainfrom
fix/crystal-ball-drag-jump

Conversation

@spydon
Copy link
Copy Markdown
Member

@spydon spydon commented May 17, 2026

Description

The center-tap handler in InputHandler was using CameraComponent.globalToLocal(event.canvasPosition) to obtain a Y coordinate, then passing it directly as a world-space target to cameraTarget.go(). However, globalToLocal returns viewport-space coordinates (0-1600 range for a 900x1600 camera), not world-space coordinates. Since the ball can be at world Y far from zero after bouncing up, this caused a large camera jump every time the user clicked anywhere in the center area.

The fix removes the broken center-tap camera movement and adds DragCallbacks so that clicking and dragging smoothly pans the camera target using event.localDelta, which is already in world-space units.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • [-] I have updated/added tests for ALL new/updated/fixed functionality.
  • [-] I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Testing instructions

  1. Run the crystal ball example: cd examples/games/crystal_ball && flutter run
  2. Click and drag anywhere on the game screen.
  3. Before fix: the camera jumps on the initial click, then stays put during the drag.
  4. After fix: the scene pans smoothly with the drag, no jump on click.
  5. Verify the left/right tap areas still trigger directional ball movement.
  6. Verify the ball still bounces and the camera follows it normally.

Related Issues

spydon added 5 commits May 17, 2026 16:01
The center-tap handler was converting canvas coordinates with
CameraComponent.globalToLocal and using the resulting viewport Y (0-1600
range) directly as a world Y. Since the ball can be at world Y far from
zero after bouncing, this caused a large camera jump on every click.

Removed the broken center-tap camera movement and added DragCallbacks so
clicking and dragging now smoothly pans the camera target via localDelta.
Directly modifying cameraTarget.position during drag was being overwritten
each frame by the running MoveCameraTarget effect (e.g. the bounce
animation), causing jank.

Add CameraTarget.nudge() which shifts both _from and _to of the animation
path alongside the position, so any active animation is preserved but
offset by the drag delta instead of fighting it.
…ra move

Only the left/right tap areas control the ball. The center-tap camera
movement used viewport coordinates as world coordinates, causing large
jumps, so it has been removed.
event.localPosition is in the InputHandler's local space (0 to size.x =
900), but the thresholds were comparing against game.size.x (the actual
canvas width). On desktop this could exceed 900, making the right tap
region unreachable and all taps fall in the dead center zone.
…ad zone

The original third-based split left a center region that did nothing useful
for ball control. Split at the midpoint so every tap moves the ball.
@spydon spydon changed the title fix: crystal ball example dragging no longer causes camera to jump fix: Crystal ball example dragging no longer causes camera to jump May 17, 2026
Copy link
Copy Markdown
Member

@luanpotter luanpotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@spydon spydon merged commit 498f982 into main May 18, 2026
8 of 9 checks passed
@spydon spydon deleted the fix/crystal-ball-drag-jump branch May 18, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants