How to make Control node shake? (And why is my code not working?)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Krasapan

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

What type of node is the parent of this control node? Many control nodes don’t allow for manual position changes of their children.

Jowan-Spooner | 2021-01-13 10:50

KinematicBody2D

Krasapan | 2021-01-14 10:43

:bust_in_silhouette: Reply From: dmitriy_shmilo
 $Tween.interpolate_property(self, "move_bar", Vector2(shake_power, shake_power), Vector2(0, 0), shake_length, Tween.TRANS_SINE, Tween.EASE_OUT, 0)

calls interpolate_property, but "move_bar" refers to a method, so you should call interpolate_method.