I cant make my character crouch, pls help

I have this code in my .cpp

 //To Crouch
GetCharacterMovement()->NavAgentProps.bCanCrouch = true;

//getting input for crouch
PlayerInputComponent->BindAction("Crouch", IE_Pressed, this, &AAccursed6Character::StartCrouch);
PlayerInputComponent->BindAction("Crouch", IE_Released, this, &AAccursed6Character::StopCrouch);

void AAccursed6Character::StartCrouch()
{
Crouch();
}

void AAccursed6Character::StopCrouch()
{
UnCrouch();
}

Hi,

Have you defined “Crouch” in the input settings? Have you checked to see if the events are firing by placing log messages in your StartCrouch and StopCrouch Methods?

Hi,

yes i have and it is working.
i think the problem is crouch();

Interesting. I see you have set NavAgentProps.bCanCrouch;.

Is the RootComponent Simulating Physics flag set to true? The only other thing I can think off is the “Crouched Half Height” ins’t set correctly. If you want to can you share your project so I can take a look?

Hi hmmm i tested it out, and it seems that the the CanCrouch and CanEverCrouch is returning false? why is that?

how do i share my project?

Are you able to zip up the project and share it from google drive. Or can you share it via GitHub or Bitbucket (Bit bucket if you want to code to remain private).

Thank you!

So CanCrouch is determined by :

!bIsCrouched && CharacterMovement && CharacterMovement->CanEverCrouch() && GetRootComponent() && !GetRootComponent()->IsSimulatingPhysics();

CanEverCrouch checks the NavAgentProps.bCanCrouch is set to true, which you are setting. Are you able to check if IsSimulatingPhysics() is returning true? This should be true, but worth the check, you never know!

hi i forgot about google drive haha, but here it is, i uploaded it in mediafire, if its lacking files i can upload more, thanks to you too! i have been stuck with this problem for atleast 2-3 days ;(

Cool! Thank you! I will have to look at this when I get home from work tonight! I hope to have an answer for you by then if thats okay!

And no problem, I have been there! hopefully we can figure it out tonight :slight_smile:

Checking this out now. I will let you know what I find!

I got the Camera to react to the crouch with your code (Copy and pasted it into third person template project). One thing I noticed is that UE4 tends to not take the constructor changes into account for the blueprint if the blueprint is already created. The only work around I know of is to either recreated the blueprint that inherits your code.

One way to check to see if your constructor is working correctly is to check the CanCrouch under the “CharacterMovement” component in the blueprint. When we set GetCharacterMovement()->NavAgentProps.bCanCrouch = true; this will make the checkbox to be checked.

If all is well you will see the camera and the movement speed react to the crouch click. From there you will need to set up the mannequin’s crouch animation. Not sure why it doesn’t come default. Here is a link to a tutorial you might find useful [link text][1]

If you still cannot get it working send me your full project and I can make the change and send it back.

228953-untitled.png

Slr man! Thanks man youre an angel hahaha, i will surely try this out! Ill let you know the results, thanms for the support

No Problem, It should work for you. I ran through it twice last night and it seemed to be the issue you had.

P.S Loved your code comments :wink:

229035-capture.png

sorry for the code comments and some swearing on my code hahahaha
hey i tested it out to see if it works on my projects side,i changed the crouched speed to 100 to see the difference, but it seems that when i press C, i wasnt slowing down ? hmm sorry
i was making sure before learning adding the animation thing.

No problem! I do the exact same thing!

You will see the camera drop down if the crouch worked. I noticed a slight walk speed change as well, but the camera was a big indicator. Also, ensure that the “Can Crouch” box is ticked in your blueprint instance of the character as seen in the image above to ensure your constructor changes took affect!

hi i found and i think i remapped the animation to my current skeleton, sooo what do i do now?, how can i use the animation?

hi, ive fixed it thanks for the support :slight_smile:

Hey sorry, Everything working?