Since the built-in functions of AnimationPlayer nodes are so limited,
I've been using this little script as an add-on whenever I need to do
anything serious with them. I thought it might be useful to others. It
lets you actually pause animations, play or reverse them from their
current position, or just resume play in the last direction—each with a
single function call. <br><br>I didn't hook up blending times since I
don't use them and it seemed like a wasted argument, but that would be
totally easy to add in if you felt like it. And I put an 'r' on each
function name to differentiate them from the default ones, you'll
probably want to change that to something that makes sense to you. <br><br>Here's the code, or just grab the attachment: <br>
extends AnimationPlayer<br><br># Implements reasonable controls for animations. Put on AnimationPlayer Nodes. <br># ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><br>var dir = 1.0<br>var t = 0.0<br>var anim<br><br>func _process(dt):<br> t = get_pos()<br><br>func rplay(animation):<br> dir = 1.0<br> play(animation, -1, dir)<br> seek(t)<br> anim = animation<br><br>func rreverse(animation):<br> dir = -1.0<br> play(animation, -1, dir)<br> seek(t)<br> anim = animation<br><br>func rplay_from_start(animation):<br> dir = 1.0<br> play(animation, -1, dir)<br> seek(0.0)<br> anim = animation<br><br>func rreverse_from_end(animation):<br> dir = -1.0<br> play(animation, -1, dir)<br> seek(get_current_animation_length())<br> anim = animation<br><br>func rresume():<br> play(anim, -1, dir)<br> seek(t)<br><br># stop() works fine as pause. <br><br>func rstop(to_start): # stops and resets time to one end or the other. <br> stop()<br> if to_start:<br> t = 0<br> seek(t, true)<br> else:<br> t = get_current_animation_length()<br> seek(t, true)<br><br>func rseek(animation, time, update): <br> set_current_animation(animation)<br> anim = animation<br> t = time<br> seek(t, update)
<p><br></p><br>