If I wanted to check if the player character is swimming, how should I do this in C++?
I know in Blueprints, it’s CharacterMovement > MovementType > Equals(enum) > Branch Node.
How would I achieve the same thing inside an if statement for C++?
If I wanted to check if the player character is swimming, how should I do this in C++?
I know in Blueprints, it’s CharacterMovement > MovementType > Equals(enum) > Branch Node.
How would I achieve the same thing inside an if statement for C++?
Almost exactly the same.
Example:
if(GetCharacterMovement()->MovementMode == EMovementMode::MOVE_Swimming))
You can reference the character movement component using
GetCharacterMovement()
From there, you can either use the EMovementMode Enum, or the bool vars, the same way you would in BP’s.
void AMyCharacter::GetCharacterState()
{
// option 1: use the MovemenmtMode enum
if (GetCharacterMovement()->MovementMode == EMovementMode::MOVE_Swimming)
{
// is swimming
}
// option 2: reference the bool vars
if (GetCharacterMovement()->IsSwimming())
{
// player is swimming
}
}