I’m following the Unreal Docs tutorials and came across this in the FPS one. I can see that the code maps the spacebar to the jump action by invoking the StartJump() function, and that in StartJump(), bPressedJump is set to true. But nowhere else in the code is it defined what bPressedJump does. I don’t see a conditional statement that says “If bPressedJump is true, then calculate the player character’s forward momentum by x and then y etc. etc.” The full code is available at the bottom of the page.
It’s in the CharacterMovementComponent class.
bool UCharacterMovementComponent::DoJump(bool bReplayingMoves)
{
if ( CharacterOwner && CharacterOwner->CanJump() )
{
// Don't jump if we can't move up/down.
if (!bConstrainToPlane || FMath::Abs(PlaneConstraintNormal.Z) != 1.f)
{
Velocity.Z = JumpZVelocity;
SetMovementMode(MOVE_Falling);
return true;
}
}
return false;
}
The class also has all the settings for jump velocity and such. You can look in the CharacterMovementComponent.h file to see that.
Ah, so it’s an inherited class! Now I understand.