x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Toggle crouching does not work c++

Hi my crouch function does not seem to work. When i press the crouch input. Nothing happens. The capsule size does not change. Is my code correct?

Player.h

 void ToggleCrouch();
 

Player.cpp

 APlayer::APlayer()
 {
       PrimaryActorTick.bCanEverTick = true;
     
      GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true;
 }
 
 void APlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
 {
     Super::SetupPlayerInputComponent(PlayerInputComponent);
 
     PlayerInputComponent->BindAction("CrouchToggle", IE_Pressed, this, &APlayer::ToggleCrouch);
 }
 
 void APlayer::ToggleCrouch()
 {
     if (GetCharacterMovement()->IsCrouching())
     {
         UnCrouch();
     }
     else
     {
         Crouch();
     }
 }
 




Product Version: UE 4.17
Tags:
more ▼

asked Jan 22 '18 at 04:35 PM in C++ Programming

avatar image

Jerelal
5 3 4 6

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

OK i figured out the solution. Ill post it just in case anyone else runs into the same issue.

 void APlayer::ToggleCrouch()
 {
     if (GetCharacterMovement()->IsCrouching())
     {
         UnCrouch();
         
     }
     else
     {
         Crouch();
         GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true;
         
     }
 }

Move this GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true; from the constructor into the Crouch function:

more ▼

answered Jan 23 '18 at 10:34 AM

avatar image

Jerelal
5 3 4 6

avatar image xlar8or Jan 23 '18 at 10:36 AM

If the issue is fixed please mark it as correct to close it :)

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question