0 votes

I have a Scene structured like this:

Node2D
  Sprite
  AnimationPlayer

The animation player has an animation called "Move" with only one track for changing the Node2D position. I create 2 instances of this scene in my Game scene, set them to different positions, and then try to utilize both of their animation players like so:

func _ready():
    var scene = load("res://Node2D.tscn")

    child1 = scene.instance()
    child2 = scene.instance()

    add_child(child1)
    add_child(child2)

    child1.set_pos(Vector2(100, 100))
    child2.set_pos(Vector2(200, 200))

    child1.move(Vector2(200, 100))
    child2.move(Vector2(300, 200))

where the move function puts a keyframe for the current position at t=0, and another keyframe for the specified destination at t=1, like so:

func move(destination):
    animation_player.get_animation("Move").track_insert_key(0, 0, get_pos())
    animation_player.get_animation("Move").track_insert_key(0, 1, destination)
    animation_player.play("Move")

My problem is that with this, child1 moves along the same animation path as child2, even though it has its own animation player. I have no idea why they don't both move along their own animation paths.

in Projects by (140 points)

I figured out my problem. Even though I am using 2 different animation players, they both reference the same animation, "Move". To fix my problem, I had to create a different animation for each child and have their animation players play the unique animation.

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.

Categories