coding animation key frames?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dumuz

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.

:bust_in_silhouette: Reply From: Dlean Jeans

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)

This is perfect, thank you.

Dumuz | 2019-12-26 16:00