Changing jumping behaviour in tps-demo

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dechows

I’m trying to learn the Godot engine my preferred way: fiddling with it while occasionally glancing the documentation.

I started with the third person shooter demo project (GitHub - godotengine/tps-demo: Godot Third Person Shooter with high quality assets and lighting). In the demo, when I jump while running, the characters movement in the xz-plane stops. I want to modify it so that the character keeps moving forward at the original speed after jumping. What do I need to change?

I already did some other movement changes in the script controlling the character ( However, the stopping of movement is not directly coded in the script, but in some way, that I don’t understand, comes from the way the jumping animation is blended to the movement. What I already checked was that I can behave the character the way I want if I simply remove the jumping animations. But is there a way to achieve what I described while keeping them and hopefully without editing the animations themselves?

:bust_in_silhouette: Reply From: davidoc

In the code the movement is taken from the player’s animation in this line:

root_motion = animation_tree.get_root_motion_transform()

This line is called two times, both when the player is on floor. In my opinion this line should be out from those IFs, just before this line:

orientation *= root_motion

This way you could modify the animation to have a displacement and then use it from the root motion, but my recommendation is to use another vector to “push” the player, this way if you need to add other forces (like wind) this vector can be used.

Use the velocity to set your push vector, do it in the jump:

if not on_air and Input.is_action_just_pressed("jump"):

add it to the character velocity before move and slide. Then you have to decide if the velocity is constant while the player is on the air or if it will decrease over time, just remember to set it to zero when player is not on the air.

Using root motion for jumping calculations is considered bad practice in game development (due to lack of predictability), but the demo does it anyway :slight_smile:

Calinou | 2020-04-10 17:41

I didn’t know it was a bad practice, maybe they used to get the translation from the jump but in the latest version that is not the case.

davidoc | 2020-04-10 20:12

Thanks. I sort of got it working by doing the following: capture the current velocity using the same get_root_motion_transform() in the if block you suggested. Then, before move_and_slide, I check if the player is on_air, and in that case I add the captured velocity to the total velocity.

However, this approach is quite buggy. For instance, if I run down an edge without jumping, it doesn’t work properly. Also the animations look a bit messed up.

I’m not a game developer and this is the first time I encounter the concept of root motion, but I am a physicist by training and I’m wondering if momentum and force based approach would make more sense. Like every action the player makes would apply a force to the body that accelerates it to some direction.

Dechows | 2020-04-11 16:20

If you want to use force you need a rigid body because kinematic is not affected by physiscs. There are many discussions about using kinematic vs rigid. Many people use kinematic because they are more predictable. Paired with root motion you can achieve a more accurate relation between animation and movement. Of course it needs practice to get the desired effect.
I have a few videos about root motion, I hope these may help you.

davidoc | 2020-04-11 17:16

Thanks. I will take a look.

Dechows | 2020-04-11 20:08