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"

How to check if player is jumping?

Hello, I recently followed Alan Noon's tutorial for creating a 2d side scroller. However this used a blueprint and I wanted to instead write it in C++, which I am new to. I've had some real trouble with changing the animation when the player jumps. I've tried using the ACharacter::IsJumping and bPressedJump and PlayerVelocity.Z > 0. I'm now completely stumped. I've searched around and couldn't find anything so I thought I'd post here.

Current code:

 void AAdventureCharacter::IsJumping()
 {
     const FVector PlayerVelocity = GetVelocity();
     
     if (PlayerVelocity.Z > 0.0f)
     {
 
         state = jumping;
         UpdateAnimation();
     }
     else if (&ACharacter::OnLanded)
     {
         state = stance;
         UpdateAnimation();
     }
 }

Update Animation:

     // Are we moving or standing still?
     UPaperFlipbook* DesiredAnimation;
     if (PlayerSpeed > 0.0f)
     {
         DesiredAnimation = RunningAnimation;
     }
     else if (state == jumping)
     {
         DesiredAnimation = JumpAnimation;
     }
     else
     {
         DesiredAnimation = IdleAnimation;
     }
     GetSprite()->SetFlipbook(DesiredAnimation);
     
 }

Here state in an Enum.

Sorry if this has already been posted, I've looked through a lot of posts and couldn't find an answer.

Product Version: UE 4.8
Tags:
more ▼

asked Dec 20 '15 at 03:39 PM in C++ Programming

avatar image

Jafferwaffer
6 1 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Try using GetCharacterMovement()->IsFalling() to check if your character is falling/jumping. I know this questions was posted almost a year ago. I was having a similar problem and thought I should post how I solved it. However, I'm just starting to use ue so there could be a better way (without using blueprints).

more ▼

answered Sep 14 '16 at 12:46 AM

avatar image

alexh714
11 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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