Skip to content

Instantly share code, notes, and snippets.

@jotson
Created April 10, 2021 18:47
Show Gist options
  • Save jotson/0b8ba288acebd19bc7cfa4a417655724 to your computer and use it in GitHub Desktop.
Save jotson/0b8ba288acebd19bc7cfa4a417655724 to your computer and use it in GitHub Desktop.
Very simple camera shake
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