How to make max speed

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Exile152

I am making an object fall, i want to have acelleration, but i also want it to cap it at a certain amout, because right now it just keeps on getting speed

var velocity = Vector2.ZERO
var velocidade = 2

func _physics_process(delta):
velocity.y += velocidade

velocity = move_and_slide(velocity)
:bust_in_silhouette: Reply From: zhyrin

The min function returns the lesser of two values.

velocity.y += velocidade
velocity.y = min(velocity.y, max_velocity)