Tween: child not moving relative to parent

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

Hello,
I have come across a problem while trying to use a tween to move a Camera2D node. I noticed the children of the node don’t seem to move together with their parent (they seem to be one frame ahead). In addition, I tried to print the following boolean value at each frame:

child.global_position.x == camera.global_position.x + child.position.x

And it is true before & after the interpolation, but while the tween is playing it alternates between true and false, which seems very strange, as I believe it should always be true in all situations.

The interpolation starts at the click of an arrow, which calls the _on_click function. Here is the script:

extends "SceneObject.gd"

export var movement_vector = Vector2(1560, 0)
onready var camera: Camera2D = get_tree().get_root().get_node("Gumba/Camera2D")

func _on_click():
    var tween: Tween = camera.get_node("Tween")
    if not tween.is_active():
	    var start_position = camera.global_position
	    var end_position = start_position + movement_vector
    	tween.interpolate_property(camera, "global_position", start_position, end_position, 1, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
        tween.start()

func _process(_delta):
    print(child.global_position.x == camera.global_position.x + child.position.x)

Here is a video of the phenomenon (the child is the blue thing to the right): https://streamable.com/f5e0ui

Thanks in advance for any help.

EDIT: I just noticed that the problem is related to whether the tween is instanced before or after the camera (in my case the tween was the camera’s child, hence instanced after it). If I move it to a position where it’s instanced before, the problem disappears. Am I missing something or is this a bug?

:bust_in_silhouette: Reply From: rakkarage

Tween position instead of global_position to move relative to parent.

Position, relative to the node’s parent.

That’s not the problem. In fact at the beginning I had used position instead of global_position, but that had this same effect. I do not want to move a child relative to its parent. In fact, what I’m tweening is the parent itself.

altermetax | 2020-09-15 17:07