A variable is a label, so var velocity = Vector2.ZERO means I can write “Vector2.ZERO” instead of “velocity”, but when I try to write Vector2.ZERO = Vector2.UP.rotated(rotation) * speed instead of velocity = Vector2.UP.rotated(rotation) * speed I received an error. Why?
You can think of a variable as a generic container that can hold some value. That value could be many things, including an integer, a string, or a Vector2 as shown below:
var a = 1
var b = "John Doe"
var c = Vector2.ZERO
However, that Vector2.ZERO reference is a value itself (it’s a shortcut for the value Vector2(0,0)). That is, it’s already a specific value, just like the number 1 and the string John Doe above. You can’t assign a value to something that’s not a variable. For instance, none of these will work:
So, while you can store a value in a variable (like the first examples), you can’t store a value directly in another value - which is what your original code is trying to do.
Thank you. It sounds simple when explained by an expert, but I couldn’t figure it out on my own.