|
|
|
 |
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 
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