Make 2D platformer player always turn for an exact, set amount of time?

Godot Version

Godot 4.6.3

I’ve been working on a 2D platformer character controller, but I’m sort of stuck on how I can smoothly make my character ALWAYS take a set amount of time to fully complete turning around when the player shifts inputs from left → right or right → left (so in essence, no matter how fast the player is going, it’ll always take 0.15 seconds to shift from going left to right)

here’s my current logic which kind of just makes the player turn INSTANTLY, since it sets their velocity to 0 skipping the need to accelerate towards the different direction entirely.

func _physics_process(delta):

    var direction := Input.get_axis("ui_left", "ui_right")
    var direction_vector: Vector2 = Vector2(direction, 0).normalized()

    if direction:

		if direction_vector != Vector2.ZERO:
			var current_accel: float
			if direction_vector.dot(velocity.normalized()) < 0:
				velocity.x = 0

		velocity.x = move_toward(velocity.x, direction * max_speed, walk_accel * delta)
		
		facing_dir = direction
	else:
		velocity.x = move_toward(velocity.x, 0, stop_decel * delta)

EDIT:

i got it down myself!! well, rather, i changed my mind on how to make it workd. INSTEAD, now my problem is in the fact that the turning animation doesn’t play fully before it’s overwritten by things like the walk. i should be able to figure it out but if i can’t that’ll be it’s own post

How many textures do you have for that turning animtion?

Have you considered a tween? Disable the player input, then enable it again when the tween finishes.