I wrote this shake code, it works great with the camera, but when I redid it to shake my Control node (there are 2 progress bars inside the Сontrol, it's called "PlayerHealthBar"), it doesn't work when called, although it should have worked 100%. What's wrong with it and how can I fix it?
The code:
extends Node2D
var current_shake_priority = 0
func move_bar(vector):
get_parent().rect_position = Vector2(rand_range(-vector.x, vector.x), rand_range(-vector.y, vector.y))
func healthbar_shake(shake_length, shake_power, shake_priority):
if shake_priority > current_shake_priority:
current_shake_priority = shake_priority
$Tween.interpolate_property(self, "move_bar", Vector2(shake_power, shake_power), Vector2(0, 0), shake_length, Tween.TRANS_SINE, Tween.EASE_OUT, 0)
$Tween.start()
func _on_Tween_tween_completed(object, key):
current_shake_priority = 0
The same code but for the camera (it works great as it should):
extends Node2D
var current_shake_priority = 0
func move_camera(vector):
get_parent().get_node("player").get_node("Camera2D").offset = Vector2(rand_range(-vector.x, vector.x), rand_range(-vector.y, vector.y))
func screen_shake(shake_length, shake_power, shake_priority):
if shake_priority > current_shake_priority:
current_shake_priority = shake_priority
$Tween.interpolate_method(self, "move_camera", Vector2(shake_power, shake_power), Vector2(0, 0), shake_length, Tween.TRANS_SINE, Tween.EASE_OUT, 0)
$Tween.start()
func _on_Tween_tween_completed(object, key):
current_shake_priority = 0