I used this tutorial to learn how to implement FPS movement and then used this tutorial to implement acceleration and friction. Before I added acceleration the player was able to stand on ramps just fine, but now after implementing acceleration the player starts sliding of the ramp when he stops how do I fix this?
physics process function:
velocity.y += gravity * delta
var desired_velocity = get_input()
if desired_velocity.x != 0:
velocity.x = lerp(velocity.x, desired_velocity.x * max_speed, acceleration)
else:
velocity.x = lerp(velocity.x, 0, friction)
if desired_velocity.z != 0:
velocity.z = lerp(velocity.z, desired_velocity.z * max_speed, acceleration)
else:
velocity.z = lerp(velocity.z, 0, friction)
velocity = move_and_slide(velocity, Vector3.UP, true)
if jump and is_on_floor():
velocity.y = jump_speed