0 votes


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?

in Engine by (12 points)

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.

1 Answer

0 votes

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
by (744 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.