The problem is that you are multiplying velocity *= RUN_SPEED
... that velocity
includes the y
component, which in _physics_process
is added with GRAVITY each frame.
So every frame, you add GRAVITY*delta
to velocity.y
and multiply it by RUN_SPEED
or WALK_SPEED
, as one of those cases will always be executed regardless if you are pressing or not a key. My suggestion is to only multiply x
component of velocity
, as RUN_SPEED
and WALK_SPEED
should only modify that component:
func get_input():
velocity.x = 0
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if is_running:
velocity.x *= RUN_SPEED #only x component
else:
velocity.x *= WALK_SPEED #only x component