How to add root motion to a 3d character fallowing a navigation mesh with godot 4 ?

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

I set up a scene with a enemy witch is fallowing markers 3D with a navemesh. I want to implement root motion, but when i do so my enemy doesn’t move any more.

Here a part of the code i made witch is working:
func MoveForBorne(delta,speed):

var targetPos = NavAgent.get_next_path_position()
var direction = global_position.direction_to(targetPos)

faceDirection(targetPos)
velocity = direction*speed

move_and_slide()

And here the code with root_motion:

func MoveForBorne(delta,speed):
var root_motion = $AnimationTree.get_root_motion_position()

var targetPos = NavAgent.get_next_path_position()
var direction = global_position.direction_to(targetPos)

faceDirection(targetPos)
velocity = root_motion*direction*speed

move_and_slide()

thank you for reading

:bust_in_silhouette: Reply From: Zesprite

I find something and it’s working:

var root_motion = $AnimationTree.get_root_motion_position()
var targetPos = NavAgent.get_next_path_position()
var direction = global_position.direction_to(targetPos)

faceDirection(targetPos)
velocity = (direction + root_motion)

move_and_slide()

I added the root_motion, instead of multiply by it.