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.





No comments:

Post a Comment