+1 vote

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!

in Engine by (21 points)

1 Answer

0 votes

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?

Thanks!

by (21 points)
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.