I have only been using unreal engine for about 2 years so there might be another way to make this. So feel free to leave your suggestions in the comments!
This tutorial will only teach you the rotation in blueprint.
Lets begin with the Animations, You have the make 4 animation for this or if you want a smoother and better way you can make it 8 animations.
Basically the 4 animations are for the dodge: Forward, Backward, Right, and Left.
As you can see here in the pictures:
The character is facing different directions in these pics as I said for Forward, Back, Right, Left. And you don’t even need anything fancy these are just static animations with only one frame. (Note: Don’t rotate the character in the z axis, focus on making the character point their hands from forward to their right for an example, look at the pics for reference)
OK! now we make a Blend Space 1D and in the Asset details below Horizontal Axis: Set the name to “Direction” and the Min Axis Value to (-180) and Max Axis Value to (180).
Now Lets go the the Graph and Place the Forward Animation on frame 90.
And place 2 Right animations on frame 180 and frame -180.
And now place the backward animation on frame -90.
And place the Left Animation on frame 0.
Save the Blend Space we are done with it.
Now go to the Animation Blueprint of the character and create a Boolean Variable and name it “Falling” Defaulted to false.
And in the event graph we are going to get a reference to the player to check if they are falling. Copy the blueprint from this pic that is going out of “Event Blueprint Begin Play” and from the Cast to “Player BP” Promote the actor to variable and name it “CharacterRef”.
And in the “Event Blueprint Update Animation” Copy this code so we can always know if the player is falling or not.
Save the Anim BP we are done with it for now.
Go to the Player BluePrint and Create an arrow and attach it to your mesh.
And then copy these in the pic below in the Event Graph.
The Reference in this pic is the Camera as “FollowCamera” and The arrow we created before as “Arrow1”.
The first part of the Sequence is for allowing the mesh to keep the rotation if they are not moving but if you want your character to always be looking at the camera direction then just remove the first part of the Sequence and set the Rotation Rate in the “Character Movement” to zero in the Z Axis.
Now Create 2 Float Variables and name them “FWRate” and “RWRate” respectively.
And go to the Movement Input Action of the Character and set the “FWRate” to the “Move Forward / Backward” Input Axis and set the “RWRate” to the “Move Right / Left” Input Axis as follows:
Now for the jump part. To sum it up in short we launch the player in the direction we are moving based on keyboard keys and we also set the player rotation to the Direction we are moving. This is important for it to work perfectly.
Go to the Jump action in the blueprint and copy the code in the picture.
(I suggest you take a look to understand what is happening so you won’t have trouble customizing it in the future)
You can also notice 2 variables that I haven’t mentioned: “JumpXRate” and “JumpZRate”. These are float variables I created they determine how far the player will be launched in the x (Forward) And z (UPward). I set them to (JumpXRate = 1000) and (JumpZRate = 600). But feel free to experiment and set them to your liking.
Also please skip the “Use controller Rotation Yaw” node and delete it if you added it to the code.
Now go back to the Animation Blueprint and open the State Machine and drag the Blend Space we made as a state and set it to transition from and to idle state.
And open the transition going from idle to falling(The blend space we made I’ve named it Falling) and in check if the variable Falling = True then we can enter transition
And then open the transition going from Falling to Idle and do the same but if “Falling” = false we can change transition.
And now the final step! Open the Falling state which is the blend space we made and set the Direction variable in the Blend Space to the Arrow Relative rotation of the z axis.
And That’s it!! We are done!
Congratulations! You are now ready to make the next Max Payne Killer!
Best Of wishes with your development!