I was working with C++ 2D SideScroller template. The character already had a chunk of code to update running animation which is working fine and looks like this:
void Aside2DcharCharacter::UpdateAnimation ()
{
const FVector PlayerVelocity = GetVelocity();
const float PlayerSpeed = PlayerVelocity.Size();
// Are we moving or standing still?
UPaperFlipbook* DesiredAnimation = (PlayerSpeed > 0.0f) ? RunningAnimation : IdleAnimation;;
if (GetSprite()->GetFlipbook() != DesiredAnimation)
GetSprite()->SetFlipbook(DesiredAnimation);
}
I was going to implement jumping and falling animation that would check Z vector. Here is the code:
void Aside2DcharCharacter::UpdateJumpingAnimation()
{
const float TravelDirection = GetVelocity().Z;
// Set flipbook if character jumped
if (TravelDirection > 0.0f)
GetSprite()->SetFlipbook(JumpingAnimation);
// Set flipbook if player falling
if (TravelDirection < 0.0f)
GetSprite()->SetFlipbook(FallingAnimation);
}
It checks Z vector and updates the flip-book, so there are no problems with that. However, if my jumping and falling flip books have 10 sprites each, it plays only the first sprite from any flip-book all the time.
It seems like it doesn’t work because of GetVelocity().Z while PlayerVelocity.Size() creates no problems. All flip-books are fine because I already tested them by swapping with running flipbbok. Any suggestions?