0 votes

This question is based off of the animationplayer node for 3D.

Is there a way to make particular key frames in an animation based off a script?

For example, I want an animation, that effects the nodes translations, to end where it started before it ever ran through the series of animations I have it run.

Essentially, I'd like a key frame that was a type of transform.origin key. This way I can send the node to animate in response to what is happening, but then at the end of the last animation that plays, it can return back to where it was smoothly.

asked Dec 24, 2019 in Engine by Dumuz (257 points)

1 Answer

+1 vote
Best answer

You can use $AnimationPlayer.get_animation() to get the Animation then call track_set_key_value() on that, plus other functions to get the track or the last_key:

var animation_name = $AnimationPlayer.current_animation # or some other name
var animation = $AnimationPlayer.get_animation(animation_name)

var track_name = 'Spatial:translation' # replace with your track name
var track = animation.find_track(track_name) # or an integer
var last_key = animation.track_get_key_count(track) - 1

animation.track_set_key_value(track, last_key, original_position)
answered Dec 26, 2019 by Dlean Jeans (3,915 points)
selected Dec 26, 2019 by Dumuz

This is perfect, thank you.

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.