From 6e600e9e6d9378f352856cfa7fc589016a6dcf4f Mon Sep 17 00:00:00 2001 From: sergeypdev Date: Sat, 2 Aug 2025 21:21:12 +0400 Subject: [PATCH] Fix jerky mouse delta on web --- game/game.odin | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/game/game.odin b/game/game.odin index d42ddd1..f0a4865 100644 --- a/game/game.odin +++ b/game/game.odin @@ -898,20 +898,23 @@ collect_camera_input :: proc() -> (delta: rl.Vector2, sense: f32, is_mouse: bool } should_capture_mouse := rl.IsMouseButtonDown(.RIGHT) - @(static) last_mouse_pos: rl.Vector2 + @(static) first_delta := true if g_mem.mouse_captured != should_capture_mouse { if should_capture_mouse { rl.DisableCursor() - last_mouse_pos = rl.GetMousePosition() + first_delta = true } else { rl.EnableCursor() } g_mem.mouse_captured = should_capture_mouse } - mouse_pos := rl.GetMousePosition() - mouse_delta := g_mem.mouse_captured ? mouse_pos - last_mouse_pos : 0 - last_mouse_pos = mouse_pos + mouse_delta := g_mem.mouse_captured ? rl.GetMouseDelta() : 0 + + if mouse_delta != 0 && first_delta { + mouse_delta = 0 + first_delta = false + } MOUSE_SENSE :: 0.005 GAMEPAD_SENSE :: 1