how to use root motion transform for moving kinematic body?

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

all tutorials say just do velocity=rootmotion.origin/delta and apply it, but it’s completely wrong:

delta is physics delta and animationtree is in process, so it has it’s own delta. Animation is not related to physics at all, and root motion transform is single frame change, so using it in physics_process is wrong.

All these examples work great in their completely empty projects where FPS is higher than physics FPS, however if it is otherwise, you’ll see that the lower your FPS, they higher wrongness of this logic is, at physics FPS at 120 (I have to use it for physics based game) and actual 40 render FPS, root motion kinematic body logic is 3 TIMES as wrong, single character step makes them fly forward and stuf

So is there anyone who can explain how to actually use rootmotion to move kinematic body?

:bust_in_silhouette: Reply From: FuLeZi

Indeed you are right. I think by dividing the delta, we do not want to ‘annihilate’ the Physics delta but the “Animation process time” delta.

For me this works with a higher physics step and lower FPS and vice-versa:

$AnimationTree.get_root_motion_transform().origin.z / self.get_process_delta_time()

get_process_delta_time() is the key here. It returns the idle frame delta time, and you can still call it inside the physics process callback if you need to.

Rodeo | 2022-01-17 21:49

:bust_in_silhouette: Reply From: Rodeo

In addition to getting the idle process delta as FuLeZi said, you can set the process mode for the AnimationTree to physics. If you look at the first picture in the manual for AnimationTree, you can see that’s what they’ve done for the demo (look in the inspector in the top right).