Saturday 30 September 2023

UE 5 Gameplay animation - Lesson 04 (Jump)

Jump is more complicated then basic locomotion, in a sense it is not just a key input resulting in one animation sequence of jump and land. Rather it consist of "jump-start" animation as a result of a key input. Follow by "falling" looped animation, activated by the drop in height of the character. Ending with a "landing" animation before going back to basic locomotion.

Due to "landing" animation needing to be additive, the basic locomotion state machine needs to separated out, to be called out later.   

First go to AnimGraph in the Animation Blue Print. Disconnect from "Output Pose" and connect to a "cached pose" naming it "locomotion. A "cached pose" is a memory node which can be called out later whenever necessary. 


Create a state machine name it "Main State Machine" and connect to "Output Pose".



Open up "Main State Machine" and create the states, name them and link them up in the correct direction accordingly.



Everything is "Add State" except two of them is "Add State Alias". 



"State Alias" is like a shortcut to state condition, instead of directly connecting to locomotion state. If there is crouched locomotion state added, it will appear in the Details and it should be ticked too. Meaning the jump can occur during locomotion state and crouched locomotion.



State condition for landing animation to occur.



Create two variables by clicking the "+". "velocity" as Vector using dropdown arrow to switch. "isfalling" as a Boolean.



Open the rule for "tofalling" to "jump". Pull in "Get velocity", right click on the circle and select "Split Strct Pin"



Add in "Greater Equal".




Add in "And Boolean".



Bring in "Get isfalling" and connect up accordingly. "Greater Equal" value of 100.



Open the rule for "tofalling" to "fall" Bring in "Get isfalling" and connect up.



Rule for "jump" to "fall" just need to tick "Automatic Rule...". So it will just move on after the jump animation is complete.



*Important: 
Because these two rules are acting at the same time, in order not to have the engine make mistake, set the priority order to 1 for the "tofalling" to "jump rule, and set to 2 for "tofalling" to "fall" rule.




Open "jump" state. Bring in the jump animation from Asset Browser on the right and connect up.



Open "fall" state. Bring in the fall animation. Tick the "Loop Animation".



Open rule for "toland" to "land". Bring in "Get isfalling" and connect to "Not Boolean" and to "Result".



Open up "land" state. Right click and add in "cached pose locomotion" and "Apply Additive". ring in landing animation and connect up accordingly.



For a better blend of landing animation, click the rule and change "duration" and "mode" to "0.1" and "cubic". This will make the landing more snappy and feel more weighty.



Rule for "land" to "locomotion" just tick "Automatic Rule...".



Open "locomotion" state. Connect up "cached pose locomotion".



Finally the variables "isfalling" and "velocity", need to be set in Event Graph. 

Open up Event Graph. Pull in "Set isfalling" and connect up.



*Tip:

Select the BP actions and press "c" to add movable window and comments. 


Pull in "Set isfalling" and "Get new character". Connect up accordingly.



*Tip:

If right click is not able to find the action. Another way is pull out from the circle and type to search.





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.