What does `move_toward(velocity.x, 0, SPEED)` do?

Godot Version

4.2.2

Question

what does move_toward(velocity.x, 0, SPEED) do? i found it in the default movement script for the characterbody2D, and can’t figure out the difference between it and just setting the velocity along that axis to 0.

You can ctrl+click on a function in scripts to open documentation on them.

it reduces velocity.x by SPEED until it reaches 0. The problem you are likely facing is that SPEED is greater than or equal to the velocity.x value. Most use move_toward and delta together.

If this is part of your _process or _physics_process it will look like this, to slow down over 1 second

move_toward(velocity.x, 0, SPEED * delta)

thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.