Tried translating a code from a tutorial for knockback.. doesn't seem to work

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

Tried this and it doesn’t react to the knockback:

var knockback = Vector2.ZERO

func _physics_process(delta):
	#knockback = knockback.move_toward(Vector2.ZERO, 200 * delta)
	#knockback = move_and_slide()
	knockback = knockback.move_toward(Vector2.ZERO, 50 * delta)
	velocity.y = move_toward(knockback.y, 0, delta)
	velocity.x = move_toward(knockback.x, 0, delta)

func _on_hurtbox_area_entered(area):
	#knockback = Vector2.RIGHT * 400
	velocity = Vector2.RIGHT * 100
:bust_in_silhouette: Reply From: MegaLuiza

I replace all the knockback variables with velocity.
Work for now, because in Godot 4 you can no longer insert a variable to move_and_slide()

func _physics_process(delta):
	velocity = velocity.move_toward(Vector2.ZERO, 100 * delta)

func _on_hurtbox_area_entered(area):
	velocity = area.knockback_vector * 100