how to use root motion with AnimationTree

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

In game development we oftens use root motion to make animation movement precisely.
But in godot Animation Tree docs did mention about how to retrieve root motion but don’t give a real example of how to use it. Do you ever experience this problem? Can you give my an usage example?

:bust_in_silhouette: Reply From: davidoc

You can apply the root motion to any object, it depends what you want to achive, you can look at the TPS Demo, they have a kinematic character and an instanced animated scene, they get the motion from the animated scene and then move the kinematic character with the velocity:

orientation *= root_motion
var h_velocity = orientation.origin / delta
velocity.x = h_velocity.x
velocity.z = h_velocity.z
velocity += gravity * delta
velocity = move_and_slide(velocity, Vector3.UP)

orientation.origin = Vector3() # Clear accumulated root motion displacement (was applied to speed).
orientation = orientation.orthonormalized() # Orthonormalize orientation.

I’ve made a few videos about root motion and the state machine here and they are based on the TPS Demo controller.

I also made an Infinite scroller where the player doesn’t move and the root motion is applied to the rooms (that project is made in C#).