UPDATE:
It seems that creating another Jump function actually doesn’t resolve the issue.
The Jump function seems to specifically be optimized, so rather than creating doJumpNoLimit() in UCharacterMovementComponent, I just updated the code within doJump to take in an extra parameter, and rather than JumpNoLimit() in ACharacter class being used, I use Jump() and just changed it to take in an extra parameter to determine if there’s a limit or not.
I kept the bJumpLimit variable, and use the Jump(bool Limited) function to change that variable in ACharacter, which is then passed through to doJump() in the CheckJumpInput function.
That probably makes no sense, but anyway, the point is, use the Jump() function, duplicate code won’t be network optimized…
For those wondering, I fixed the problem with a simple solution, but it took ME a while due to my lack of programming experience and re-learning C++ Syntax and flow again.
The limiter was found in the CharacterMovementComponent.cpp 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)
{
// Check the maximum of either Velocity.Z or JumpZVelocity and set the character Velocity.Z to that value. This is a limiter when jumping. No momentum added per jump however.
**Velocity.Z = FMath::Max(Velocity.Z, JumpZVelocity); <-----CHANGE THIS LINE**
SetMovementMode(MOVE_Falling);
return true;
}
}
return false;
}
Because I created 2 jump functions in the Character.cpp class, I changed the above to this:
bool UCharacterMovementComponent::doJumpNoLimit(bool bReplayingMoves)
{
if (CharacterOwner && CharacterOwner->CanJump())
{
// Don't jump if we can't move up/down.
if (!bConstrainToPlane || FMath::Abs(PlaneConstraintNormal.Z) != 1.f)
{
//Simply add to current velocity
**Velocity.Z = Velocity.Z + JumpZVelocity;**
SetMovementMode(MOVE_Falling);
return true;
}
}
return false;
}
I can make this better if I want to, by adding a parameter that takes in a limiting value, or if left at 0, would be unlimited, and I will probably actually try to implement this shortly.
I wanted to have 2 separate jump functions, one which is the standard jump function, another which is “DoJumpNoLimit”, purely just so I’m not destroying any original functions.
In order for me to do this, I created a JumpNoLimit() function in the Character.cpp class which uses the same code from the Jump() function.
I also have a boolean set up called “JumpLimited” inside of the Character class and by default this value is set to true.
I now have the following inside of Character.cpp:
void ACharacter::Jump()
{
bLimitJump = true;
bPressedJump = true;
JumpKeyHoldTime = 0.0f;
}
void ACharacter::JumpNoLimit()
{
bLimitJump = false;
bPressedJump = true;
JumpKeyHoldTime = 0.0f;
}
And in the same class, I changed the CheckJumpInput(); function so that it checks to see if there should be a limit or not, which is decided if the player uses Jump() or JumpNoLimit();
void ACharacter::CheckJumpInput(float DeltaTime)
{
if (CharacterMovement)
{
//IF this is a LIMITED Jump
if (bPressedJump && bLimitJump)
{
// 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++;
JumpForceTimeRemaining = GetJumpMaxHoldTime();
OnJumped();
}
}
bWasJumping = bDidJump;
}
//IF this is NOT a LIMITED jump
else if (bPressedJump && !bLimitJump)
{
// 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->DoJumpNoLimit(bClientUpdating);
if (bDidJump)
{
// Transition from not (actively) jumping to jumping.
if (!bWasJumping)
{
JumpCurrentCount++;
JumpForceTimeRemaining = GetJumpMaxHoldTime();
OnJumped();
}
}
bWasJumping = bDidJump;
}
}
}
And…yeah that’s about it for my fix, I just hope that if someone is trying to do something similar, that they can refer to this and have a solution