Created
April 10, 2021 18:47
-
-
Save jotson/0b8ba288acebd19bc7cfa4a417655724 to your computer and use it in GitHub Desktop.
Very simple camera shake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cameraShakeIntensity = 0.0 | |
var cameraShakeDuration = 0.0 | |
func shake(intensity, duration): | |
if intensity > cameraShakeIntensity and duration > cameraShakeDuration: | |
cameraShakeIntensity = intensity | |
cameraShakeDuration = duration | |
func _physics_process(delta): | |
# Camera shake | |
var camera = Game.Camera | |
if camera and cameraShakeDuration > 0.0: | |
cameraShakeDuration = cameraShakeDuration - delta | |
if cameraShakeDuration <= 0: | |
# Reset camera | |
camera.offset = Vector2(0,0) | |
cameraShakeIntensity = 0.0 | |
cameraShakeDuration = 0.0 | |
else: | |
# Shake camera randomly | |
camera.offset = Vector2(randf() * cameraShakeIntensity, randf() * cameraShakeIntensity) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment