Last active
June 2, 2018 03:11
-
-
Save lukewilson2002/c48c40daac3bef77439da63d30244ed7 to your computer and use it in GitHub Desktop.
3D Godot GDScript camera shake script.
This file contains 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
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