2D SideScroller Template: Jumping

Hey there,

I just created a new 2D SideScroller project from the template inside UE4. I noticed, that for the jumping the functions


Jump();

and


StopJump();

get called inside the C++ code. However, I don’t find any definitions for those functions inside the code.

I was curious on what the best way is, to implement jumping in C++ in a 2D project and thought that might be a good start to look it up. But now I still don’t know anything. :smiley:

Can anyone point out where those functions get defined or how they work? Are those some functions that come within UE4 since I can’t find it neither in the .h nor in the .cpp file so I thought it might be inside one of the many includes of headerfiles.

Sorry if this might be a dumb question but I am just starting out using UE4 and C++.

Thanks in advance!

Edit: I did make a post on Reddit about this. Just in case somebody is upset because of cross-posting. Didn’t get any answers there so far and thought, here might be a better place to ask.

Use VS2017 or VS2019 “Go to” (Edit->Go to, Shortcut Ctrl+T) command to find symbols.

(Or Find in Files(Ctrl+Shift+F), Lock in Entire Solution)

Jumping finally modify UCharacterMovementComponent Velocity.Z and MovementMode.

// Character.cpp



void ACharacter::Jump()
{
    bPressedJump = true;
    JumpKeyHoldTime = 0.0f;
}

void ACharacter::StopJumping()
{
    bPressedJump = false;
    ResetJumpState();
}

void ACharacter::CheckJumpInput(float DeltaTime)
{
    if (CharacterMovement)
    {
        if (bPressedJump)
        {
            // If this is the first jump and we're already falling,
            // then increment the JumpCount to compensate.
            const bool bFirstJump = JumpCurrentCount == 0;
            if (bFirstJump && CharacterMovement->IsFalling())
            {
                JumpCurrentCount++;
            }

            const bool bDidJump = CanJump() && CharacterMovement->DoJump(bClientUpdating);
            if (bDidJump)
            {
                // Transition from not (actively) jumping to jumping.
                if (!bWasJumping)
                {
                    JumpCurrentCount++;
                    OnJumped();
                }
                // Only increment the jump time if successfully jumped and it's
                // the first jump. This prevents including the initial DeltaTime
                // for the first frame of a jump.
                if (!bFirstJump)
                {
                    JumpKeyHoldTime += DeltaTime;
                }
            }

            bWasJumping = bDidJump;
        }

        // If the jump key is no longer pressed and the character is no longer falling,
        // but it still "looks" like the character was jumping, reset the counters.
        else if (bWasJumping && !CharacterMovement->IsFalling())
        {
            ResetJumpState();
        }
    }
}


CharacterMovementComponent.cpp



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;
}