Godot Version
v4.5.stable.mono.official [876b29033]
Question
This is my code:
public void HandleAnimation(IHasState owner, float moveDirection,
bool isJumping, bool isFalling)
{
if (owner.State == PlayerState.Default) {
HandleHorizontalFlip(moveDirection);
HandleMoveAnimation(moveDirection);
HandleJumpAnimation(isJumping, isFalling);
} else if (owner.State == PlayerState.Hold) {
HandleHorizontalFlip(moveDirection);
HandleHoldAnimation(moveDirection);
} else if (owner.State == PlayerState.Frozen) {
animationPlayer.Play("get_hit");
} else if (owner.State == PlayerState.Defeated) {
animationPlayer.Play("defeat");
}
}
The problem - this method is being called on loop in PhysicsProcess of the Player class. Frozen means the player has been damaged. Defeated means player health is zero. In both cases player will stay in this period for a short while at least, in case of defeat as long as defeat popup menu is active. And during that time those animations are constantly called on loop, so they play on loop, instead of playing only once and staying on last frame.
Animation Player has an option to customize animation looping: play once, loop, or play from start to end and from end to start. I have it set to play once, but animation player is not really concerned about it. I understand why, but it’s very unintuitive.
So I want to figure out how to bypass this problem. I have a bunch of code-first solutions in mind, but I want to know if there is very easy or GUI based solution for it. I don’t want to take out cannons to kill a fly.