Hi! I want to create a sound when I jump like in 2d games, but I have a problem. part of the code:
void AGameCharacter::JumpStart()
{
if (bIsJumping != true)
{
bIsJumping = true;
UGameplayStatics::PlaySound2D(this, Sound);
}
Jump();
}
when I click on the space (Jump input) bool “IsJumping” equals truth, and if this bull equals truth, it reproduces sound, but when my character lands on the floor after jump bool “IsJumping” doesn’t switch to false, I thought I could fix it if I find a vector z, but I don’t know how to do it on c++, but if you have another solution, please answer me. Thank you!
Override Landed(const FHitResult& Hit)
in the character and use it to reset your variables.
Hi! Sorry for the late reply. Thank you! I tried to do something I got this:
Header:
void Landed(const FHitResult & Hit);
CPP:
void AGameCharacter::Landed(const FHitResult & Hit)
{
bIsJumping = false;
}
and it works, thank you! But can you check this part for correct syntax and etc.?
Thank you very much!
If you’re overriding a function, better do it explicitly:
void Landed(const FHitResult & Hit) override;
And call the parent function in case something is done there:
void AGameCharacter::Landed(const FHitResult & Hit)
{
Super::Landed(Hit);
bIsJumping = false;
}
Just to make sure everything in the parent class will work too.
Thank you!!