Preparation
Download a character you like from Mixamo, along with a set of animations, and import them into Unreal to prepare for building the animation state machine.
Duplicate the existing Character Blueprint in your project, replace its skeletal mesh with the one you prepared, and adjust capsule/ collision parameters as needed.
Create an Animation Blueprint and a Blend Space as shown.
Then assign the newly created Animation Blueprint to the Character Blueprint.
Next, create a GameMode Blueprint so we can direct the game to use our custom character.
Create a new level and open World Settings.
In World Settings, set the GameMode Blueprint you created, and configure your Character Blueprint.
Set Up the Animation State Machine
Idle, SlowRun, FastRun Animations
Open the Blend Space you created and place the Idle, SlowRun, and FastRun animations. You can hold Ctrl and move the mouse in the preview to observe how the animations blend.
In the Animation Blueprint, create your first state — Locomotion — by dragging the asset into the state machine.
Create a variable BS_Speed_Input and wire it as the input for Horizontal Speed in the Blend Space.
With the basics in place, the last step is to pass the character’s Velocity into BS_Speed_Input so the animation state machine actually runs.
Go back to the Blend Space graph and add the blueprint logic (this also contains the upcoming logic for pressing F to enter Fight). The general idea is: first fetch the character’s Velocity via component queries; then get the character’s Animation Blueprint Class and set a Fighting Bool there; finally propagate this Bool to isFighting, which we’ll use to drive fighting state transitions.
After connecting everything, click Play to do a first pass test for Idle / SlowRun / FastRun.
Fighting Animation
Next, build out the complete Animation State Machine logic and set up proper transition rules/frames. The overall layout is as follows:
After that, configure the Fighting input logic in the Character Blueprint. Earlier in the Animation Blueprint we ensured that the Fighting value is forwarded into isFighting, so changing Fighting will also change isFighting. Here we simply set it so that pressing F sets isFighting to True and releasing F sets it to False. Now the character can attack by pressing F.
However, there’s still a bug: the attack animation is an on-the-spot attack, but we didn’t prevent movement during attack. We need to fix that. To also ensure there is no movement during transitional animations (e.g., recovering from fighting back to idle), we add a new variable isRecovering. The character can move only when not isFighting and not isRecovering. Also, when not isFighting, isRecovering will delay and then become False. The blueprint logic is as follows:
没有评论:
发表评论