I'm tying to add animation keys from code but it's not working. I have a rectangle (
Container node) and I want it to move it size to the left, wait the
duration time and go back to the original position. I also want that the show and hide animation (slide to the left then to the right) have one second lenght.
The code that I'm using is this one:
var anim = $Animation.get_animation("move")
var pos = $Body.rect_position
var size = $Body.rect_size
anim.track_insert_key(0, 0, pos)
anim.track_insert_key(0, 1, Vector2(pos.x-size.x, pos.y))
anim.track_insert_key(0, 1+duration, Vector2(pos.x-size.x, pos.y))
anim.track_insert_key(0, 2+duration, pos)
The rectangle moves to the left but does not go back to the original position. I did some debugging using
for loops to see if the keys times and values were all correct and they were fine.
What am I doing wrong?
Edit: If I only change the key value from code instead of creating the keys, it works.