Enabling Crouch within C++

Have this code from a past project in a first person character class constructor:

#include "PawnMovementComponent.h"

// enable crouching
if (GetMovementComponent())
{
	GetMovementComponent()->GetNavAgentPropertiesRef().bCanCrouch = true;
}

Couple issues to be aware of: when the character crouches you will have to shrink the collision capsule. Also, out of the box Unreal characters have issues with jumping and crouching within a few ticks. We did a workaround where if you jump the crouch would wait to happen for a few ticks.

6 Likes