How do i Play Attack Animation While In Air?

Hello game developers. I am new to unreal game development. Here is my issue:

So i have my character walking around playing animations. Which is fine, but i want a certain Attack Animation to play pressing a button only when player is in air. How would i go about doing that?

In my animation state machine i have a state going from JumpStart to a state called **Attack. **This Attack state has the attack animation to play while player is in air. Any help would be very much appreciated. I would love for screenshots of step by step of how i can accomplish this.

Thanks in Advance.

Its probably a easy thing to do but i am probably missing something.

Hi!

I’m going from memory here. But you need an “inAir” variable or something to know that your character is in the air. So in the animation blueprint that you make from “Event Blueprint Update Animation” you “try get pawn owner”, “Get Movement Component”, “Is falling”. This will return a bool to update your variable “inAir”. Now your blueprint knows if the character is in the air or not. This then can gate your action. When you press your action button there must be a branch that checks “inAir” first. If true then the attack can happen. If false then nothing.

Is that what you’re after?

Here’s some images to help.

And here’s my animation graph. I did this a while back so I can’t remember what’s going on. But my character can attack while running using this slot. The animation only plays on the upper half of my character’s body.

Here is how i have mine setup (still not working) the player uses the attack animation in replace of the “JumpLoop” animation i have setup in the state machine.

Here is what my state machine looks like:

Here is what i have setup inside the rules defining the attack animation playing:

Rule going from Attack back to JumpLoop

Here is what the Anim Graph looks like:

ds

Here is what the Event Graph inside the Animation Blueprint looks like:

Here is inside my character blueprint:

Please respond with any problems you find that i have not done correctly, thanks.

It’s an attack. just use montages. Watch/follow all of this

The animation is a montage i put that into a default slot which gets called in the anim graph

I just need a way to call that montage to play when the attack button is pressed when player is in air.

Drag off the movement component, type air, and see what you find.
alternatively the movement component has/runs a line trace that can tell you the distance off the floor. You could piggyback onto that trace and use a > 0 to determine if you could attack or not.

Note that this will also be true any time you are falling.
if that isnt suitable, use your Jumping boolean or create one if you don’t have one already.

Thanks for all your guys help, i figured it out. I setup the attack montage and used that animation in the state machine going from “JumpLoop” to “Attack” and in the player character blueprint, i created a keyboard action event, i created a Boolean variable called “AttackInAir” and for the Pressed i set it to true and for the Released i set it to false. And in the Animation Blueprint in the Event Graph i cast to my player character Blueprint and for the object, that goes into “Try Get Pawn Owner” and you can access the “AttackInAir” Variable by dragging from “As third person BP” and search for “Get Attack In Air” and from that you can drag out and promote to variable and hook up that up. And of course making sure that in the Anim Graph you setup the slot for the animation montage. That done it for me.