I am trying to make a 3D movement system that accelerates/decelerates the player instead of just setting their speed to a value. So far it is working prity well and feels smooth, but I have come across an issue. I do not know how I can prevent the player from decelerating when in the air whilst still allowing the player to move around in the air slightly. Here is my code:
func accelerate(delta):
var temp_vel := velocity
temp_vel.y = 0
var temp_accel : float
if !Input.is_action_pressed("run") and is_on_floor():
target = direction * speed
else:
target = direction * run_speed
if direction.dot(temp_vel) > 0:
temp_accel = acceleration
elif is_on_floor():
temp_accel = deceleration
if !is_on_floor():
temp_accel = air_control
temp_vel = temp_vel.lerp(target, temp_accel * delta)
velocity.x = temp_vel.x
velocity.z = temp_vel.z