How can I set up crouching in UE?

Hey! I have been having some difficulty on getting a good crouch going for my game. I am using this code at the moment, which works pretty well:

void AFPSCharacter::StartCrouch()
{
	if (CharacterMovement->IsMovingOnGround())
	{
	isCrouched = true;
	CharacterMovement->bWantsToCrouch = true;
	}
}

void AFPSCharacter::EndCrouch()
{
	if (CharacterMovement->IsMovingOnGround())
	{
	isCrouched = false;
	CharacterMovement->bWantsToCrouch = false;
	}
}

The problem is that the player crouches immediatly, without any type of crouching motion or delay, so it looks very unnatural. This on the other hand, works perfectly…

void AInstinctCharacter::StartCrouch()
{
	if (CharacterMovement->IsMovingOnGround())
	{
    Crouch();
	}
}

void AInstinctCharacter::EndCrouch()
{
	if (CharacterMovement->IsMovingOnGround())
	{
	UnCrouch(true);
	}
}

…but “EndCrouch()” does not work for whatever reason. Anyone know why? Thank you in advance! I implemented it as follows:

	InputComponent->BindAction("Crouch", IE_Pressed, this, &AFPSCharacter::StartCrouch);
	InputComponent->BindAction("Crouch", IE_Released, this, &AFPSCharacter::EndCrouch);

Hi Borzi,

In EndCrouch(), change the line UnCrouch(true); to UnCrouch(); and see if that resolves your issue.

Perfect, thank you.

Hi Borzi,

Keep in mind that the generally preferred method for making a character crouch is by setting the value of bWantsToCrouch to true (and false to make the character return to its normal stance). However, if the method above meets your needs, then you should be fine.

Yeah, it works a lot better actually.