+1 vote

Hi,
each of my Inherited scenes randomize its position in _ready() function. After this it changes first point of Sprite position [Animation] track to the same value

var anim = $Animation.get_animation("move_to_pos_zero")      
var track_pos =anim.find_track("Sprite:position") 
anim.track_set_key_value(track_pos,0, $Sprite.position)

The problem is with the reference of [Animation] node. Each of my "child" scenes inherit the same [Animation] node, so each new inherited node override animation position-track value of other nodes.

screen

For example: I create three of Inherited scenes. Each scene randomize its position on init and set the same value to position-track(id 0) of [Animation] node. After this each node plays "movetopos_zero" and animates its position to (0,0). Unfortunly first and second initialized nodes teleportate to position of last created node and do the same animation.

The question is how to make [Animation] unique?

Sorry for my English. I hope you understood what I meant.

Godot version 3.2.3
in Engine by (19 points)

1 Answer

0 votes

An Animation is inherted from Resource, so you can use all methods from Resource on your Animation.
This let's you use duplicate().

So you could do:

var anim = $Animation.get_animation("move_to_pos_zero") .duplicate()

But then you would have an entire new Resource, so you would have to set this new Resource as the Resource in use for you AnimationPlayer:

$Animation.add_animation("my_animation_name", anim)

(don't forget, that you old animation "movetopos_zero" is still in the list of the AnimationPlayer, so you can't use that name for you new animation)

But to achieve your goal I would rather use Tweens, as you can give them a start and an endpoint and they whil interpolate from start to end over a give period of time. (Look into the docs for more information)

by (16 points)
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.