–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

asked Oct 24, 2019 in Projects by zlSilverStar (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.

answered Oct 25, 2019 by kidscancode (17,668 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.