This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

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 (https://github.com/godotengine/tps-demo). 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 (https://github.com/godotengine/tps-demo/blob/master/player/player.gd). 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?

in Engine by (20 points)

1 Answer

+2 votes
Best answer

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.

by (1,002 points)
selected by

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

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.

Thanks. I sort of got it working by doing the following: capture the current velocity using the same getrootmotiontransform() in the if block you suggested. Then, before moveandslide, I check if the player is onair, 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.

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.

Thanks. I will take a look.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.