I'm hoping somebody can help me to understand what is happening here. I'm putting in two snippets of code
func _physics_process(delta):
if Input.is_action_pressed("ui_left"):
velocity.x = -speed
elif Input.is_action_pressed("ui_right"):
velocity.x = speed
elif Input.is_action_pressed("ui_down"):
velocity.y = speed
elif Input.is_action_pressed("ui_up"):
velocity.y = -speed
move_and_slide(velocity)
velocity = velocity.move_toward(Vector2.ZERO, friction)
and this one:
func _physics_process(delta):
var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
velocity = input_dir * speed
move_and_slide(velocity)
velocity = velocity.move_toward(Vector2.ZERO, friction)
Both work, and my character moves. In the first code, the move_toward is working brilliantly, and I can control the easing of the character by changing the friction value. On the second code, the easing doesn't work at all. When I print(velocity), I can see the friction value changing the velocity back to ZERO gradually in the first code, whereas in the second code I go from max speed to zero immediately. Does somebody know why move_toward is not working in the second code?