–1 vote

I got an error in my project: SCRIPT ERROR:

movement_loop: Invalid operands 'Vector2' and 'int' in operator '+'.

[Here is the movement loop thingy]:

func movementloop():
var motion = movedir.normalized() + SPEED
move
and_slide(motion, Vector2(0, 0))

.

how can i fix it? :c

in Engine by (11 points)

1 Answer

0 votes

movedir is a Vector2, such as (1, 0) and SPEED is an integer, such as 50. You can't add a vector to a scalar.

Likely you meant var motion = movedir.normalized() * SPEED. Multiplying a vector by a scalar is allowed - it takes your normalized (length 1) vector and scales it up to your desired speed.

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.