Godot Version
4.2.1
Question
I decided to try some YouTube tutorials, to learn to build a game totally from scratch. Exactly at the point where the presenter taught me how to move the character everywhere efficiently, the code he provided looks like this:
if direction:
velocity.x = direction * SPEED
anim.play(“Run”)
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
anim.play(“Idle”)
This is just giving me the ability to move to the left and the right. I became quite bored, so I decided to mess around with the said code a little bit. Experiment on the velocity.x values a few times until I learned my character’s pace varied depending on the changes I made.
When my line is like this, it did a wee slide after it stopped moving:
velocity.x = move_toward(velocity.x, 0, -100)
Subsequently, I replaced the velocity.x and it looks like it was pulled by some magnet:
velocity.x = move_toward(100, 0, -100)
And then it went the other way after I made the value negative:
velocity.x = move_toward(-100, 0, -100)
While this is trivial, I really would like to understand the math behind it. I want to know how and why the numbers alone made a very significant difference given that the results are not what something I kind of expected (e.g. the character became faster, or slower). Who knows it can be super helpful to new developers like me to make something impressive out of it.
Thank you in advance.
Edit: Fixed the initial quote and improved the vocab