Hello, I recently followed Alan Noon’s tutorial for creating a 2d side scroller. However this used a blueprint and I wanted to instead write it in C++, which I am new to. I’ve had some real trouble with changing the animation when the player jumps. I’ve tried using the ACharacter::IsJumping and bPressedJump and PlayerVelocity.Z > 0. I’m now completely stumped.
I’ve searched around and couldn’t find anything so I thought I’d post here.
Current code:
void AAdventureCharacter::IsJumping()
{
const FVector PlayerVelocity = GetVelocity();
if (PlayerVelocity.Z > 0.0f)
{
state = jumping;
UpdateAnimation();
}
else if (&ACharacter::OnLanded)
{
state = stance;
UpdateAnimation();
}
}
Update Animation:
// Are we moving or standing still?
UPaperFlipbook* DesiredAnimation;
if (PlayerSpeed > 0.0f)
{
DesiredAnimation = RunningAnimation;
}
else if (state == jumping)
{
DesiredAnimation = JumpAnimation;
}
else
{
DesiredAnimation = IdleAnimation;
}
GetSprite()->SetFlipbook(DesiredAnimation);
}
Here state in an Enum.
Sorry if this has already been posted, I’ve looked through a lot of posts and couldn’t find an answer.