Animatablebody2d reverse significantly slower then playing

Godot Version

`4.4

Question

I made a shop open animation where it slides in using an animatablebody2d
And for some reason, when closing the shop, it is a lot slower than when opening it

Code ↓

extends TextureButton


func _on_pressed() -> void:
	if Global.shop_open == false:
		$"../AnimationPlayer".play("new_animation")
		Global.shop_open = true
	else:
		$"../AnimationPlayer".play_backwards("new_animation")
		Global.shop_open = false
	print(Global.shop_open)

Hi there, the reason it’s playing slower is most likely due to the fact that you are using play_backwards()
This method is a shorthand for play() with custom_speed = -1.0 and from_end = true. Which makes it go in reverse. I would wager a guess that the animation has a speed that is higher than 1 (which is why it’s slower when it closes)

You can fix this like so:


		$"../AnimationPlayer".play_backwards("new_animation", !custom_speed)

This should by default set the animation speed to the reverse of what it is

I haven’t really used this before but if it doesn’t work just switch “!custom_speed” with the opposite of whatever speed you have for your animation.

Also I would suggest you name your animations and for future reference I found this solution by checking the documentation for the AnimationPlayer node. You can find this by right clicking on the node and then pressing “open documentation” in the pop up menu. And then scrolling down to the play_backwards method and reading about how it works

Hope this helps :slight_smile:

Thanks!
Is there a way to rename an animation?

Also, it didn’t work, but the reason it didn’t work was because the animation time was longer than the actual animation, so that was the problem

Is there a way to rename an animation?

yes, if you go to the animatedsprite2d node and then double tap the “new animation” text that is to the left of the actual animation and then you can just type whatever you want it to be called. (and remember to replace the stringname in your code with the new name or you will get an error)
:slight_smile:

alr thanks