0 votes

Take a look at this kinematicBody2d movement code.

if Input.isactionpressed("Right")
velocity.x += 1

How does Adding (velocity.x) Paired with the symbol (+= ) And with number (1) Makes it move?

in Engine by (18 points)

1 Answer

0 votes

That code doesn't make anything move. It just adds 1 to the x component of a Vector2 variable called velocity.

Since the word "velocity" means "change in position over time", that variable is likely being used later in the script to change the object's position, something like

position += velocity * delta

For example, or some other method, depending on what type of object it is.

by (20,677 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 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 webmaster@godotengine.org with your username.