Third Person Shooter (Unity Tutorial) Ep 2 Animation Blend Trees
Table of Contents
Introduction
In this tutorial, you will learn how to animate a player character in Unity using blend trees. This guide is based on Episode 2 of the Third Person Shooter series by Gadd Games. By the end of this tutorial, you'll have a player model set up with various animations that are primed for integration with a finite state machine in the next episode.
Step 1: Downloading Player Model and Animations
- Go to Mixamo to find and download animations and a player model.
- Select a character model you like and customize it as needed.
- Download the character with the desired animations in FBX format.
- Save the files to a location on your computer for easy access.
Step 2: Setting Up the Player Model in Unity
- Open your Unity project and navigate to the Assets folder.
- Import the downloaded FBX model into Unity:
- Right-click in the Assets window and select "Import New Asset."
- Locate your FBX file and click "Import."
- Create a new folder in the Assets directory for organization, e.g., "PlayerModel."
Step 3: Setting Up the Animations
- In Unity, select the imported player model.
- In the Inspector window, find the "Animation" section.
- Ensure the animations are set to loop if required (e.g., for walking or running).
- Drag and drop the animations into the Animator window to prepare for blend tree creation.
Step 4: Adding the Player to the Scene
- Create a new GameObject for the player:
- Right-click in the Hierarchy window, select "Create Empty" and name it "Player."
- Drag the player model from your Assets into the Player GameObject in the Hierarchy.
- Adjust the position and scale of the player model as needed.
Step 5: Animator Setup
- Select the Player GameObject and open the Animator window.
- Right-click in the Animator window and select "Create Blend Tree."
- Name the blend tree (e.g., "MovementBlendTree").
- Double-click the blend tree to edit it and add parameters for various movements.
Step 6: Creating the Walking Blend Tree
- In the Blend Tree, add a new animation for walking.
- Set up the blend parameters:
- For example, use the speed of the player to determine the blend between idle and walking animations.
- Adjust the thresholds to achieve smooth transitions between animations.
Step 7: Creating the Crouching Blend Tree
- Add a crouching animation to the blend tree.
- Set up conditions for transitioning into and out of the crouch state based on player input.
- Ensure that the crouch animation blends smoothly with the walking and idle states.
Step 8: Creating the Running Blend Tree
- Add a running animation to the blend tree.
- Configure the parameters to allow for a seamless transition from walking to running based on speed.
- Test the transitions to ensure they feel natural.
Step 9: Setting Up Transitions
- In the Animator window, create transitions between the blend trees (e.g., from idle to walking).
- Set the conditions for these transitions based on the parameters you configured earlier.
- Ensure each transition has appropriate exit time and duration settings for smooth animation changes.
Step 10: Testing the Animations
- Play the scene in Unity to test the animations.
- Check for any issues with blending and transitions.
- Adjust parameters and thresholds in the blend trees as necessary to improve responsiveness.
Conclusion
You've successfully set up a player model with blend trees in Unity for walking, crouching, and running animations. These animations are essential for creating a responsive and immersive gameplay experience. In the next episode, you will integrate these animations with a finite state machine to enhance character behavior. Keep refining your animations and testing them in different scenarios for the best results.