Godot Version
4.5
Question
Hi guys! I want my character to have some acceleration before entering its top speed so I tried modifying the basic 2D movement template:
direction = Input.get_axis("move_left", "move_right")
if direction:
velocity.x = move_toward(velocity.x, direction * SPEED, ACCEL*delta)
#accel being the acceleration modifier
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
It somewhat works. However when I quickly switch directions the character keeps some of the momentum from the initial movement making them slide a little. after using print() i figured out it’s because when you quickly switch from one direction to the other it skips the second line of code responsible for setting the velocity back to 0
Is there a way to prevent this? I am new to Godot and know almost nothing about programming so I ask for your understanding.