Figured it out. Here's the code for anyone interested:
_physics_process(delta: float):
var root_motion := animation_tree.get_root_motion_position()
var input_direction := Input.get_vector("left", "right", "forward", "back")
var direction := transform.basis * Vector3(input_direction.x, 0, input_direction.y)
var current_rotation := transform.basis.get_rotation_quaternion().normalized()
var horizontal_rotation = camera_rig.global_transform.basis.get_euler().y
var horizontal_velocity = current_rotation * root_motion / delta
direction = Vector3(input_direction.x, 0, input_direction.y)
direction = direction.rotated(Vector3.UP, horizontal_rotation).normalized()
velocity = Vector3(horizontal_velocity.x, velocity.y, horizontal_velocity.z)
if direction:
rotation.y = lerp_angle(rotation.y, atan2(direction.x, direction.z), lerp_weight)