Hi folks,
I have already created my crouching functionality in Unreal (which is not rocket science) but I am struggling to find a way to enable crouching within C++
Of course, you can easily tick the (Can Crouch) box within the character blueprint (Character Movement> Nav Movement> Movement Capabilities> Can Crouch). However, I looked through the documentation for how to implement this within C++ and on the web and I can’t find anything helpful.
The “CharacterMovementComponent.h” library only has a couple of functions: CanEverCrouch() or CanCrouch() but they only return the boolean as opposed to setting it.
Help will be much appreciated.
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
@Shmoopy1701 You are a star!
I knew that it involved all the commands in that line but I couldn’t figure out a way of putting it together.
Thanks a lot again
P.S. In my case I didn’t need the (#include “PawnMovementComponent.h”) as already had this in my source file:
#include “GameFramework\CharacterMovementComponent.h”
(Epic should really enable crouching by default)
1 Like