Scene sometimes blinks while dragging with smoothTime and/or draggingSmoothTime set to zero
Shne opened this issue · comments
Describe the bug
If I have smoothTime
or draggingSmoothTime
(and especially with both) set to zero, the whole scene will sometimes blink while moving the camera with the mouse. I'm not sure whether the camera position is momentarily reset to something else, or whether the scene actually has a problem rendering, but I'm not getting any runtime errors in the console.
Version 2.0.1.
I haven't tried a version below 2 yet, but I'm guessing that's when the bug was introduced, since it introduced smoothTime and draggingSmoothTime.
To Reproduce
Steps to reproduce the behavior:
- Go to https://yomotsu.github.io/camera-controls/examples/basic.html
- In the browser console, execute
cameraControls.draggingSmoothTime = 0
and/orcameraControls.smoothTime = 0
. - Move camera with the mouse, and you might see the scene blink for what seems like a single frame, when pressing or releasing the mouse.
- It seems easier to cause the blinking when holding the mouse button only for a short time, and moving the mouse only a little bit. So try moving the mouse in a small circle and clicking rapidly.
It doesn't seem like both variables need to be set to 0 for blinking to occur, but it occurs more easily when both are 0. At least one of them needs to be 0 for the blinking to occur.
Setting them to something small but non-zero, like 0.00000001
does not cause the blinking to appear. This makes me think maybe a division-by-zero could be the culprit.
Sometimes, with only one variable set to zero, (i.e. this doesn't seem to happen with both at zero), the camera will for the single frame seemingly be looking straight down, as I can see the ground wireframe pop up in the sky at a flat angle.
Code
No response
Live example
No response
Expected behavior
I expect the scene not to blink while dragging.
Screenshots or Video
No response
Device
Desktop
OS
Windows
Browser
Chrome, Firefox
Looking at the source code, it could potentially be these lines:
https://github.com/yomotsu/camera-controls/blob/dev/src/CameraControls.ts#L2237
https://github.com/yomotsu/camera-controls/blob/dev/src/CameraControls.ts#L2247
as they make a division by draggingSmoothTime
and smoothTime
, respectively, which would cause changedSpeed
to be Infinity
, which could throw the camera to directly above or below for a single frame before, I expect, it would be corrected back to the target position.
I'm not sure if just comparing draggingSmoothTime
and smoothTime
against 0, and skipping the block if it's 0, would be a fix.
Sorry for the delay. I've been quite busy recently...
And thanks for investigating.
I'll fix this.
This has been solved with v2.1.0
Let me close this issue.