📜 ⬆️ ⬇️

Create a 2D platformer using the Unreal Engine 4. Part 1.5 - Jumping


A full “part 2” will be devoted to the combat system, but I haven’t yet brought it to the desired state, but I didn’t want to write anything at all for 2 weeks, so for now let's deal with a small expansion of our character’s abilities.

In the last article, we prepared a character and a simple scene, learned to move horizontally, it's time to learn, if not fly, then at least jump!


')



Minor project changes:
  • Found a new storyboard, redid all sprites Alucard, now, as it should be, he is in red
  • Added small platforms made from the texture of the floor for training jumps
  • Added background pictures for atmosphere :)






First we need to prepare the animation. How to do this is described in Part 1 , for convenience, I prefer to divide the jump into 2 conditional parts - jump and fall. To the top point in the air, we lose the first animation, after, respectively, the second. Animation of the fall can also be used when, in fact, falling from the edge of a cliff or other obstacles. We prepare Flipboocks, it should be noted that the playback speed and the duration of the display of individual frames is selected individually.





Next, turn, in fact, to work out jumps. Go to our character's Blueprint, add a jump event handler - InputActionJump. This is a simple keystroke handler, it has two states - it is pressed and released. In principle, you can directly add the jump function to the keystroke, it will work, but we are trying to do well, right? Last time we started to make a system for changing animations, it expands easily and can be very flexible, so we will use it.
To switch the animation, we need to know that the key was pressed, so we add a Boolean variable to the input and translate it into a state of truth. Thus, we will track the keystroke, after which there is a jump and resetting (false) our variable, with a delay - the animation takes some time.
To release the key, add another Boolean variable - we will need it later. As a result, we obtain a simple algorithm:
Jumping




Expand our animation system. We have a new opportunity, so let's add a branch to the choice of animations: check if the character can jump (built-in function, thanks to the guys from Epic Games), if it can jump, we’re after the earth, go to the existing branch, if not, we’re air and animation need others.
Jump animation change branch


The logic here is simple: if we can not jump, then we must determine for what reason - we either jump or fall. In the first case, we consistently lose the jump / fall, in the second only the fall.

Testing:




Part 1 - Game character, movement

Source: https://habr.com/ru/post/239143/


All Articles