I would like to know why the following code does not work if I have the code that handles movement in its own function and then call it in the physics process function, moving the code out of the movement function and into the physics process works but I would like to know why my version of the code does not work.
This function declares it’s own velocity, we call this “Shadowing” as the previous velocity from CharacterBody2D is now inaccesable. For clarity let’s re-write this function without using pre-existing variable names
In this version we see that the real velocity is never changed, only the function’s copy of velocity.
The easiest solution to your problem is to declare movement without velocity or input as arguments, this will use the CharacterBody2D’s definitions instead.