I didn’t want to use Launch Character function, so I went in and overrode CanJump and added a jump counter that resets OnMovementModeChanged (checking when you land).
CanJump does return true, but when I press the jump button in the air, nothing happens.
I tracked the function down to CharacterMovementComponent and I see DoJump in there:
bool UCharacterMovementComponent::DoJump()
{
if ( CharacterOwner )
{
// Don't jump if we can't move up/down.
if (FMath::Abs(PlaneConstraintNormal.Z) != 1.f)
{
Velocity.Z = JumpZVelocity;
SetMovementMode(MOVE_Falling);
return true;
}
}
return false;
}
Would adding to the Velocity.Z rather than setting it help? Also, is there any other way around this, I don’t want to have to make a new class extending CharacterMovementComponent just to override this one function.
Thanks!
-R
Shamless bump.
I’ve also considered changing the jumpZvelocity when you jump so compensate, but seeing it in action, I’m not really sure this is the issue, so I’m not really sure where to look next.
-R
While I can’t say why it wasn’t working with my method, I found a more simple solution (duh).
This answerhelped me out.
I simply manually set the Z speed for the movement component from within my character class.
For anyone interested in implementing something like it, added a JumpCount to my character class,
overrode
bool AMyCharacter::DoJump(bool bReplayingMoves)
{
if (CanJump())
{
JumpCount++;
return CharacterMovement->DoJump();
}
else if (!CanJump() && JumpCount < 2)
{
JumpCount++;
CharacterMovement->Velocity.Z = CharacterMovement->JumpZVelocity;
return false;
}
return false;
}
You may also want to override the virtual function
void AMyCharacter::OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PrevCustomMode)
{
Super::K2_OnMovementModeChanged(PrevMovementMode, CharacterMovement->MovementMode, PrevCustomMode, CharacterMovement->CustomMovementMode);
if (PrevMovementMode == EMovementMode::MOVE_Falling && CharacterMovement->MovementMode == EMovementMode::MOVE_Walking)
{
JumpCount = 0;
}
}
to reset your jump count and do any event handling.