shoot'em up ship smooth rotating animation playing forward and backward

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

Hi, i’m pretty new at godot and i’m trying to make a 2d side scroll shootem’up game.

I have a problem making the classic smooth rotation animation for up and down movement (like gradius).

I have an idle animation which is static, and up and down animations rotating on opposite directions (along the y axis).

Anytime the input direction change it has to rotate in the opposite direction passing through all intermediate frames starting from the current. Also, if the player is not moving it also has to smoothly return to idle.

For example, using current animations:
When the ships is moving up i play the up animation and if i press down while up is still playing it has to play the up animation backwards from current frame go throught idle animation and play down animation.

What is the best way to do it?

Thanks in advance!

:bust_in_silhouette: Reply From: Mostrio

I found a possible solution myself. I post it here because can be useful for someone:

I handle the animation all by code. I have only one animation with all rotation frames which is set but not playing.

This function is called every frame updating current animation frame using user input (the y_velocity)

func update_animation(y_velocity: float, delta: float):
var idle_frame: float = num_frames * 0.5
var timing_multiplier = delta * fps
if y_velocity == 0 and current_frame != idle_frame:
	y_velocity = 1 if (current_frame < idle_frame) else -1
	timing_multiplier = clamp(timing_multiplier, 0, abs(idle_frame - current_frame))

current_frame = clamp(current_frame + y_velocity * timing_multiplier, 0, num_frames)
if ($AnimatedSprite.frame != current_frame):
	$AnimatedSprite.frame = current_frame

Has someone any other solution using built in tools?