Skip to content

Instantly share code, notes, and snippets.

@WolfgangSenff
Created December 9, 2022 14:10
Show Gist options
  • Save WolfgangSenff/007d2587da00abf3f2df523636eebd92 to your computer and use it in GitHub Desktop.
Save WolfgangSenff/007d2587da00abf3f2df523636eebd92 to your computer and use it in GitHub Desktop.
A horizontal shake method to help add hit stops to your games!
extends Node
# Make this a global singleton if you want
func shake_horizontal(thing, strength: float) -> void:
var orig_pos = thing.position
var current_amount = 6
var shake_count = int(abs(current_amount))
for i in shake_count: # Tweak these values
var tween = create_tween().tween_property(thing, "position", Vector2.RIGHT * pow(-1, i) * strength * current_amount, 0.01)
await tween.finished
current_amount *= .75
thing.position = Vector2.ZERO
# Will add all-ways shaking in the future, after I've implemented it!
@WolfgangSenff
Copy link
Author

This is for Godot 4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment