The game I currently am working on is quite heavy on all kinds of jumps, so I dedicated some time to investigate how to configure UE4 character jumps properly. Some random values I put in Jumping / Falling section of Character Movement component did not work well for me:
I drew a trajectory of my jumps before I started tweaking the config values. You may notice that they are not symmetrical – the reason for that is the character (a lamp in my case) speeding up horizontally during a jump. This does not make sense for projectile motion.
Physics behind UE4 character jumps
Recently I watched a very good video from GDC conference. The speaker told about jumps in games and more important – physics behind jumps. I recommend you to watch this video first – I am going to use physics formulas of projectile motion which perfectly described in the video:
Surprisingly, UE4 character jumps fit common physics laws really good. And I will show you in the next section how to configure the settings properly, so the jumps become more predictable.
First, let’s make jumps symmetrical. I would like to get this out of the way before setting up anything else.
In my case, this happens because I use Add Movement Input node to move the character. The character speeds up horizontally with an acceleration which does not make sense for projectile motion – initial speed should be the maximum speed during the whole jump. I could not figure out how to turn off the acceleration, so I just put a huge number in Character Movement / General Settings / Max Acceleration value. 100000 should be enough:
In the video above there were two important formulas which describe speed and gravity dependency on height and time:
where v0 is an initial vertical speed, h – jump height, th – time to reach the height, g – gravity
Note here, that only gravity and initial vertical speed can be configured in UE4 with the use of the following variables: gravity scale and jump Z velocity. Height and time depend on these variables.
Say you want a jump 100 cm height which takes 1 sec to complete. Then, gravity should be:
Or in terms of UE4, the gravity scale should be 0.8163. The vertical speed, on the other hand, should be:
Let’s check if this math works:
Great! It works. Now, for my game I want gravity to be the same as on Earth, i.e. 980 cm/sec2. In such requirements, according to the first formula I either choose a time to reach the maximum height or a target height. I cannot configure both. Let’s say, I still need a 1 sec jump because it matches my jump animation. In this case, the target height will be:
And the speed:
Let’s move on to jump distance settings. In the video there were again two formulas:
Where vx – horizontal speed and xh – distance to the jump peak. I use Add Movement Input to control the horizontal speed, so vx will match max speed UE4 variable. And xh is not configurable.
Let’s again check if this works at all. I want a 1 second jump and which is 120 cm length. I don’t change the initial vertical speed, but I adjust the horizontal speed:
and the result:
As you see jumps in Unreal Engine 4 are highly configurable and likely you won’t need to implement a custom jump system.