You will have to excuse me again, but I misread your code... I'm deeply sorry for the wrong information previously.
You are doing the steps correctly. (notice that you are basically reseting the vector when the horizontal_direction
is 0). Just for sanity check before I look for something more obscure/complex, have you considered lowering the wall_jump_knockback
? It's quite higher than the other values, maybe set it to 300? You also could use a lerp()
function instead of the clamp()
and see if it smooths the movement a little, something like:
velocity.x = lerp(velocity.x, horizontal_direction * max_speed, acceleration)
instead of
velocity.x += horizontal_direction * acceleration * delta
velocity.x += clamp(velocity.x, -max_speed, max_speed)
(There is nothing wrong with your current method, but maybe the first one will do a more smooth movement)
Also, in the if statement that checks is_jumping
, maybe is it better to set velocity.y += jump_speed
instead of velocity.y = jump_speed
. Lastly, does it have any significant difference if you move the velocity.y += delta * gravity
to be just before the move_and_slide()
method?
Again, sorry for the wrong information early, check if any of this adjustments fix the movement now.