0 votes

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
Godot version 3.2.3.stable
in Engine by (91 points)

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

KinematicBody2D

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.