How to accelarate upto a constant speed at the beginning of the game?

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


See image.

At the beginning of the game I want the white and red circle to accelerate upwards to a set speed and then maintain that speed for the rest of the game. How can I achieve this?

Try setting a variable like game_running to an initial value of False, and change it to True in the _ready() function.

Then, in the _physics_process(delta) function, have an IF statement that will check for ‘game_running’ to be True. if game_running == true:

Then, we can accelerate. We’ll need a Vector2 with a negative Y value.
We can use the clamp() method to keep the speed within a specific range.

System_Error | 2020-04-07 16:15

:bust_in_silhouette: Reply From: supper_raptor

You can do this

var max_speed = 100
var speed = 0
var acceleration = 10 

#any direction you want ,currently pointing upward
var dir = Vector2(0,-1)

func _process(delta):
	speed = min(max_speed, speed + acceleration * delta)
	position += dir * speed * delta