Not certain that this is the optimal method but it could certainly be done this way:
Add an AnimationTree, add a NodeBlendTree and select your animation player. Add the node structure as:
Animation --> TimeScale --> Seek --> Output
In the AnimationTree script make method along these lines:
var playing_segment = -1
func play_segment(start):
if playing_segment == -1:
set("parameters/Seek/seek_position", start)
set("parameters/TimeScale/scale", 1)
playing_segment = start
Then to stop the animation add a Call Method Track in your animation player calling a stop_segment()
method in your animation tree. You can use the playing_segment
value to add some logic here and make sure the right animation stops in the right place depending on which segment is playing. Remember to reset it to -1 when you're done.
Here are the docs for animation_tree if you're not familiar with it:
https://docs.godotengine.org/en/stable/tutorials/animation/animation_tree.html