Mobile Game Progression

Creating Mid-Air Attack

Now that our player can jump, dash and also air dash, the next reasonable thing to add is to add in mid-air attack, where the player is able to attack during mid jump. This is quite useful for the players if you decide to add in enemies or interactive objects that are floating in the air or in places that are not ground level.

Adding the Animation to the player:

Thanks to filebase, we are already provided with an mid air jump attack sprite sheet. All we have to do is slice it into the proper cell size and import them into an newly created animation.

In the Animation window we are going to create a new animation and name it Jump Swing. We are going to adjust the 2D box collider to just be active when when swing reaches the front of the player, then it deactivates after.

Next in the Animator window we are going to make the “Jump Swing” stat transition from the “Any State” using the already created “Attack” and “Jumping” parameter as the set condition.

For the transition out of the “Jump Swing” we are going to the Idle state where the preset condition is to have the “Jumping” parameter set to false.

Player Animation & Trigger the Jump Swing Action:

In the player animation script, just like how we have preset all the other playre animation, we are going to do the same for the Jump Swing.

Start by creating a new public method called “Jump Attack”, within this method we are going to toggle the parameters that we have set within the Animator, so the Jumping parameter must be set to “true” while the Trigger “Attack” must be called. The Arc effect is also called to give the swing some motion. (this is the same effect motion as the regular swing, if you have extra assets or want to add your own variations this is where you will call the animation)

In the Player script inside the Movement method, we are going to setup a new if statement when the player is “NOT” grounded and the attack button is pressed, we are going to toggle the player animation “jump attack”.

Once you saved our script, we can test the new functions back in Unity.

nice and smooth.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.