Why this error?!

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zlSilverStar

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 movement_loop():
var motion = movedir.normalized() + SPEED
move_and_slide(motion, Vector2(0, 0))

.

how can i fix it? :c

:bust_in_silhouette: Reply From: kidscancode

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.