+1 vote

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)

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?

in Engine by (13 points)
edited by

1 Answer

0 votes

Tween position instead of global_position to move relative to parent.


Position, relative to the node's parent.

by (1,879 points)

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.

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 Frequently asked questions and 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 [email protected] with your username.