–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
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 (21,527 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.