Skip to content

Instantly share code, notes, and snippets.

@lukewilson2002
Last active June 2, 2018 03:11
Show Gist options
  • Save lukewilson2002/c48c40daac3bef77439da63d30244ed7 to your computer and use it in GitHub Desktop.
Save lukewilson2002/c48c40daac3bef77439da63d30244ed7 to your computer and use it in GitHub Desktop.
3D Godot GDScript camera shake script.
extends Camera
func shake(length, magnitude):
var time = 0
var camera_pos = translation
while time < length:
time += get_process_delta_time()
var offset = Vector3()
offset.x = rand_range(-magnitude, magnitude)
offset.y = rand_range(-magnitude, magnitude)
offset.z = 0
var new_camera_pos = camera_pos
new_camera_pos += offset
translation = new_camera_pos
yield(get_tree(), "idle_frame")
translation = camera_pos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment