Fix frame-rate dependent camera rotation and zoom in CameraControls#8494
Fix frame-rate dependent camera rotation and zoom in CameraControls#8494slimbuck merged 1 commit intoplaycanvas:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes frame-rate dependent scaling in CameraControls by separating rate-based inputs (which should integrate over dt) from delta-based inputs (which already represent per-frame deltas), preventing rotation/zoom blow-ups during frame hitches.
Changes:
- Clamp
dtto 100ms as a safeguard against extreme per-frame integration for rate-based inputs. - Split input scaling into rate-based multipliers (keyboard/gamepad/virtual joystick) vs delta-based multipliers (mouse/touch/wheel).
- Update rotation/zoom application sites to use the appropriate multiplier type.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| update(dt) { | ||
| dt = Math.min(dt, 0.1); | ||
| const { keyCode } = KeyboardMouseSource; |
There was a problem hiding this comment.
dt is clamped in-place and then passed through to this._controller.update(frame, dt), so this changes controller integration/damping (and focus transitions) during long frames, not just rate-based inputs. If the intent is only to cap keyboard/gamepad/joystick rates, consider using a separate rateDt = Math.min(dt, 0.1) for the rate-based multipliers while still passing the original dt into the controller, or update the PR description to explicitly call out the broader behavioral change.
Summary
dt, causing camera rotation and zoom to blow up during frame hitchesdtto 100ms as a safety net for rate-based inputs (keyboard/gamepad movement)Details
CameraControlsapplied* 60 * dtmultipliers uniformly to all input types, but there are two fundamentally different categories:dtis correct.dtdouble-counts the time component.At 60 FPS the
* 60 * dtfactor equals 1.0 so the bug was invisible, but at lower frame rates or during hitches the camera would massively overshoot. For example, a 1-second hitch would amplify mouse rotation by 60x.The fix splits multipliers into rate-based (with
dt) and delta-based (withoutdt), and applies the correct one at each usage site. Behavior at 60 FPS is identical.