Hello, I’m fairly new to C++, and here’s where I’m currently at:
- I’ve set up a MyCharacter class derived from the Unreal Character.cpp class.
- I currently enable crouching for the character when the “Shift” button is pressed, and disable crouching when the “Shift” button is released.
- One thing I’m trying to do is to allow the player to jump whilst “crouch” is held down, and then also to go back into “crouch” on landing without taking their finger off the button.
Here’s my Jump() override function:
void ABlasterCharacter::Jump()
{
Super::Jump();
if (bIsCrouched)
{
UnCrouch();
bWaitingToJump = true;
}
UE_LOG(LogTemp, Display, TEXT("Woooooooo!"));
}
I’ve also added the following in my Tick() function:
void ABlasterCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
//NOTE: Don't re-order bWaitingToCrouch and bWaitingToJump!
if(bWaitingToCrouch)
{
CrouchButtonPressed(); // this just calls Crouch();
bWaitingToCrouch = false;
}
if(bWaitingToJump)
{
Jump();
bWaitingToJump = false;
bWaitingToCrouch = true;
}
}
The main problem I’m having is that the Crouch() and Jump() functions both want to wait until the next update to be called, and I think Jump() only gets called if Crouch() hasn’t been called.
What I have seems to work, but it feels like there must be a better way than putting this functionality in Tick(). Is there another way of doing this (without using a delay)?