Rotating character relative to the camera AND the direction they're moving in

Godot Version

4.5.1

Question

I have a setup where the player character, the camera, and the player’s model are separated and are linked together via remotetransform3D’s
so the setup is like

CharacterBody3D
-Collisionshape3D
-RemoteTransform3D - linked to Node3D
-RemoteTransform3D - linked to model

Node3D
-Camera3D

Model

what I want to do is to have the model turn in the direction of the player’s movement relative to the camera
the player itself rotates towards the camera direction as soon as movement begins and stops rotating when the player isn’t moving

this is the abysmal code- it’s not at all what I want from it because I don’t get how this shit works

extends Node3D

@onready var cam = $"../Node3D"

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
	var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if direction:
		$".".rotation.y = cam.rotation.y + (direction.y) + (direction.x)

Control camera and model by script instead via remote transform nodes.