Skip to content

mgolucino/Unity3D-MeleeComboTutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

Unity3D-MeleeComboTutorial

Preview

Instructions

Download the MeleeComboTutorial folder and import it into your Unity 3D project. If you open up the demo scene, you will see that the scene is fairly empty and missing certain objects. You must go to the Unity Asset Store and download a free animation package to obtain the rest of the assets used for this tutorial.

Fighting Motions Vol.1

Fighting Motions Vol 1 Search for Fighting Motions Vol.1 in the Asset Store and import the package into your Unity project. Once the package is done importing, the demo scene should look similar to the first image shown above. We will only be using six of the animations included in this package, which are listed below:

* idle_A
* hp_straight_left_A
* hp_straight_right_A
* hp_hook_left_Tiramis
* hp_upper_right_A
* bk_rh_right_A

To easily find these files, use the search bar on the Project window and copy/paste these names. You may delete the other animations or place them in a different folder so that you have an easier time locating the animations needed for this tutorial. At this point you can proceed to the tutorial.

Animation Events

Animation Event Times The first half of making melee combos is defining the earliest points in time at which your animations can transition to the next attack. This is done through Animation Events. For this tutorial, we are going to name the event NextAction. The best place to define NextAction is right after the momentum of an attack has ended; placing it any earlier will cut your animations too short, while placing it any later may cause a jarring delay between player inputs and attack transitions. The image above shows a good place to define NextAction for each of the five attack animations.

MeleeAttack.cs

Animation events do nothing without a corresponding public void method of the same name to call the event. A C# script called MeleeAttack.cs contains a public void method called NextAction() that activates the NextAction trigger in the animator whenever an animation event is called. The other trigger in the script, MeleeAttackA, reacts to player input and tells the animator when to proceed to the next attack. You may examine the script by double clicking on MeleeAttack.cs in the Scripts folder.

The Animator Controller

Initial Animator The second half of making melee combos is setting up animation states and transitions in the animator controller. Go to the Animations folder to find the animator controller - there should be an initial and complete version of the controller. Double click on the initial version to open up the Animator window. The animator should look like the image above, with the idle and attack states already set up for you. Each animation state should contain a StateHandler component which allows some code to execute each time the animator enters a different state. Do not change the values on StateHandler to prevent unintended results. With the animation states all set up, all you need now is to create the transitions between states.

Transitions Between Attack States

Transitions Between Attack States Transition Times For each attack state excluding the last, create a transition that leads to the next attack. Click on one of the transition arrows to view its properties in the inspector. Uncheck the box for Has Exit Time and add the NextAction and MeleeAttackA triggers for the conditions. Do this for all four transitions so that your animator controller looks like the image above. Then, expand the Settings drop-down menu and set the Transition Duration for each transition to the values shown in the image above.

Transitions Back to Idle

Transitions Back to Idle When making or looking for attack animations, it is good practice to have the character model return back to the idle pose by the end of the animation. This way, we don't have to rely on the animator to interpolate back to the idle state itself, which may result in silly looking transitions. As the animation package we downloaded does this for every attack animation, we only have to set up the transitions to prevent any smoothing or interpolation between animation states. Create a transition arrow for each attack state back to the idle state, and click on one of them to view the transition properties in the inspector. Expand the Settings drop-down menu to view even more properties. Set the exit time to 1, the transition duration to 0, and the transition offset to 0. These settings allow the idle state to play right after the end of the attack animation, with no smoothing between the end of the one state and the beginning of the other. Do this for all five transitions back to idle so that your animator controller looks like the image above.

Finishing Touches

Finished Animator To finish up the animator, make a transition from idle to the first attack of your combo sequence. Use MeleeAttackA as the trigger and make sure to uncheck the box for Has Exit Time. The completed controller is shown on the image above. You can now press play on the demo scene and test out the combo sequence; five attacks should play one after another if you press the E key five times in quick succession. If you decide not to press the E key after an attack, the character should return to the idle animation. If you are not sure that you have set up the animator controller correctly, you may compare your animator controller with the complete animator found in the Animations folder.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages