Sunday 17 September 2023

UE 5 Gameplay animation - Lesson 03 (Basic locomotion)

Lets dive into creating basic locomotion. There are variety of ways to configure the animation, but the logic is more or less the same. The current configuration are extracted from on the video below, credits to GorkaGames



Create "New Character" folder, "Animation" folder. The basic locomotion sequence can be downloaded from the details of the YouTube video above. And stored in "Locomotion" folder.



In "Animation" folder, create Animation Blueprint (ABP). 


Go to AnimGraph. Right click and create Animation State Machine.


Name it "Locomotion" and connect to "Output Pose".


Double click on "locomotion" to open it up. Right click, add state, name accordingly. Connect them up by left click and pulling from the border of the box. The circle icon between the arrows are the conditions/rules for the transition to happen. The "stops" is to add in walk stop animation for a nicer transition to idle. It still works if it goes from "Entry" to "idle" to "walk/run" and back to "idle". Meaning if the speed is at zero the animation will just switch to idle.


Open up "Idle" state. Click the Asset Browser from the right side. Search for "Idle" and drag Idle sequence into the blank space. Idle sequence can be any idle animation. Connect to Output Animation Pose.


*Tips:

1. History locations shortcut for quick access.

2. Backwards or Forward a location.

3. Full Location path. Can be accessed by clicking.



Open "Stops" state. Pull in "Walk_Stop" and connect up.


Before going to "walk/run" state, go back to Content Browser, "locomotion" folder, right click and create Blend Space 1D. 


Make sure to choose the correct skeleton.



In Asset Details on the left, under Horizontal Axis, enter "speed" for name, "500" for Maximum Axis Value.



Drag and place "Walk_InPlace" at speed "0". Do the same for "Walk_forward" at speed "250". Do the same for "Run_forward" at speed "500". At speed "0" it can also be idle sequence but "Walk_InPlace seems to work better for blending. Once done save it and close.



Go back to Animation Blueprint, AnimGraph, and open up "walk/run" state.



Drag in BS_locomotio_1D and connect up accordingly. 



Right click on the "speed" connector. Select "Promote to Variable".



This is the result. 



Next is setting up all the rules/conditions. Open the one between "idle" and "walk/run".



Drag in the "speed" variable, and click on "Get speed". 



Bring out the Actions List by, either dragging out from the connector to blank space, or right click on blank space. Find "Greater" and select it.



Connect them up accordingly. 

*Tips:

1. Select all the action boxes and press "Q" to quick align them.


Open the rule between "walk/run" and "stops". Add "speed" variable and "Less Equal" and connect up.



"stop" to "idle" state rule does not need to add any actions. In the Details on the right, tick "Automatic Rule Based on....". This will let the animation sequence finish 1 time before switching to next state. Under Blend Settings the amount of blend between the animation can be adjusted as required.



With the State Machine done, next is the Event Graph which sets up the measurement of character variables. Just follow the video at 14:06 to at least get this for the basic locomotion to work.



ABP is completed. Remember to click "Compile" and save often. "Compile" will implement all the actions of the Blueprint. Sometimes there is error message but can be ignored, because some parts of the blueprint is not complete.



Go to Content Browser. Use the existing or duplicate the "BP_Third Person Character". Open it up.



In Details on the right, select the ABP created earlier for Anim Class. And select the correct Skeletal Mesh. Compile and Save.



Finally, open up "BP_Third PersonGame Mode" from the same folder. Select the correct "BP_Third Person Character" for Default Pawn Class. Save it.



Click the Play button on any of the Blueprints or go to ThirdPersonMap tab to press the Play button. Basic locomotion should be working now. 



Subsequent Lessons will be adding more actions like jump, crouch, etc. 

No comments:

Post a Comment