How to make speed increase with movement (acceleration)

4.3

I’m trying to make a driving game, and I want the speed to accelerate while the car is moving. How can I do that?

I assume you mean it’ll keep constantly accelerate until a max?

    if "whatever you're using to find the direction":
        velocity += direction * acceleration * delta
        velocity = velocity.limit_length(max_speed)
    else:
        velocity = velocity.move_toward(Vector2.ZERO, acceleration * delta)
    move_and_slide(velocity)

sorry I’m really new to Godot and I’m not sure of your code

but my movement code is this:

	#Movement.
	var input_dir := Input.get_vector("right", "left", "backward", "forward")
	var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if direction:
		velocity.x = direction.x * speed
		velocity.z = direction.z * speed
		car.look_at(position - direction)
	else:
		velocity.x = move_toward(velocity.x, 0, speed)
		velocity.z = move_toward(velocity.z, 0, speed)

	move_and_slide()

it is inside a physics procces (delta) function

Try something like this, pretty simple:

var max_speed := 20.0  
var current_speed := 0.0 
var acceleration := 0.5  
# acceleration is how fast u get the car to max_speed.

if direction:
    current_speed = min(current_speed + acceleration, max_speed)
    velocity.x = direction.x * current_speed
    velocity.z = direction.z * current_speed
    car.look_at(position - direction)
else:
    current_speed = max(current_speed - acceleration, 0)
    velocity.x = move_toward(velocity.x, 0, current_speed)
    velocity.z = move_toward(velocity.z, 0, current_speed)