To do screenshake, you can walk through smooth noise over some duration, multiply by a max screen offset, and then set the camera's offset equal to this.
The problem is that when the camera is near its limits, adjusting the offset in the direction of the limit won't do anything. This creates a very ugly asymmetrical shake.
Is there a way to adapt the technique so it works when a camera is near the perimeter of its limiting rectangle?
After some experimentation, it should be possible to get around this problem by accessing the default
CanvasLayer of the root
Viewport (and any other
CanvasLayers used in the scene) and manually adjusting their
Transform2D. That said, I'm not sure exactly how to do that, or how to achieve a single pixel shift using the
Transform2D of the
CanvasLayer. Any help is appreciated.
Can obviously do something like:
get_tree().get_root().canvas_transform.x.x += .001
get_tree().get_root().canvas_transform.x.y += .001
get_tree().get_root().canvas_transform.y.x += .001
get_tree().get_root().canvas_transform.y.y += .001
But the shifts look distorted in windowed mode (though look fine in full screen). Also, how to determine what value corresponds to a pixel?