My approach to max_fall_velocity

You can set the max fall velocity more smoothly with a bit of maths (based on Drag, which gives Terminal Velocity)

The max fall velocity occurs when gravity equals drag force, i.e. reducing all the constants to a single constant drag, giving gravity = drag * max_fall_velocity * max_fall_velocity after a bit of rearranging and cancelling. You get the following code to calculate the effective drag to give the max_fall_velocity

var relative_fall_velocity = velocity.y / max_fall_velocity
velocity.y += gravity * (1 - relative_fall_velocity * abs(relative_fall_velocity)) * delta

The absolute value accounts for the velocity direction since drag always pushes the velocity toward zero.

Note: we do need delta here as acceleration (i.e. gravity and drag) is a change in velocity over time; move_and_slide() only accounts for the change in position based on velocity.

Privacy & Terms