Quick answer: Skip one frame of mouse delta on OnApplicationFocus(true). Clamp per-frame delta to a sane maximum (e.g. 200 px) to prevent spike-induced view snaps.
User alt-tabs to another window, comes back; the camera spins wildly for one frame. The OS reports the cursor’s new position as a single huge delta.
The Symptom
Camera snaps after focus loss/regain or display change. Repeatable. Not present in normal play.
The Fix
private bool _skipNextDelta;
void OnApplicationFocus(bool hasFocus)
{
if (hasFocus) _skipNextDelta = true;
}
void Update()
{
if (_skipNextDelta)
{
_skipNextDelta = false;
return;
}
Vector2 d = Mouse.current.delta.ReadValue();
d.x = Mathf.Clamp(d.x, -200, 200);
d.y = Mathf.Clamp(d.y, -200, 200);
RotateView(d);
}
Skip one frame of input on focus regain; clamp deltas to bound any other anomalies.
Verifying
Alt-tab and return. Camera should not snap. Test multiple monitors / display swaps. Without the fix: snap. With: stable.
“Skip on focus. Clamp delta. Camera holds.”
Related Issues
For multi-touch fingerId, see touchId. For input action double-fire, see double-fire.
Skip the spike. Clamp the rest.