Translate move_toward from Godot 3.5 to Godot 4

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

Hi. I’m porting an early project into Godot 4, and my knockback/attack-dash stopped working, the move_toward function is not moving the knockback vector to zero like in Godot 3.5. It’s a 3D game.

Code example from 3.5 where it works inside the attack function:

knockback_vector = knockback_vector.move_toward(Vector3.ZERO, 50 * delta)
knockback_vector = move_and_slide(knockback_vector)

The knockback_vector is the last input direction if you attack, and one between you and your enemy when you get attacked so I can reutilize the code.

This was the latest attempt at Godot 4:

velocity = knockback_vector.move_toward(Vector3.ZERO, 50 * delta)
velocity += knockback_vector

The move_toward is not reducing knockback to 0 like this, is there a bug or am I blatantly wrong in this approach?

:bust_in_silhouette: Reply From: Moot Point

Solved, just had to try some more stuff

		knockback = knockback.move_toward(Vector3.ZERO, 50 * delta)
		velocity.x = move_toward(knockback.x, 0, delta)
		velocity.z = move_toward(knockback.z, 0, delta)

This worked just like I wanted it.