Animation and direction in 2.5D

Godot Version

4.3.stable

Question

Wasn’t sure where to put this exactly. I’m fairly new to programing but I was having some difficulty trying to save a direction value. I have an 8 directional player sprite pasted onto a CharacterBody3D. I want to be able to save last input vector to program in my animations between idle and walk-cycles but so far can’t figure out how to store it. This is what I am working with so far.

func _physics_process(_delta):
	
	var input_direction_2D = Input.get_vector(
		"left", "right", "forward", "back"
	)
	
	var input_direction_3D = Vector3(
		input_direction_2D.x,0.0,input_direction_2D.y
	)
	
	velocity.x = input_direction_3D.x * move_speed
	velocity.z = input_direction_3D.z * move_speed
	
	
	move_and_slide()