No worries! Here, I'll try to demystify the maths too for you:
2) Like this: RayCast2d.cast_to.normalized()
Normalising gives a new vector in the same direction a length/magnitude of 1 known as a unit vector
.
So Vector2(0, 14).normalized()
normalised is Vector2(0, 1). You calculate this by working out the length and then dividing the vector by it. Working out the length is pythagoras: so Vector2(0, 14)/sqrt(x*x, y*y)
So, Vector2(0/14, 14/14) in this example.
4) There are two ways to multiply vectors; dot and cross products. The dot product is the simplest. You put in two vectors and you get a number out. In code it's looks like this: Vector2(1, 0).dot(Vector2(1, 0))
the result is a scalar (a number) - in this case 1.
In maths it's first_vec.x * second_vec.x + first_vec.y * second_vec.y
When dealing with normalised vectors (99.9% of the time you will be), the dot product is a measure of how similar they are. So, a dot product of 1 means that they are pointing in the exact same direction. A dot of -1 means that they are pointing in opposite directions. Zero is perpendicular/orthogonal (but it doesn't tell you which way, if the dot is zero and you rotate 180, you still have zero).
This why there's step 3, by rotating 90 degrees. If you didn't do that you'd know they were misaligned because the result would be less than 1 but you wouldn't know wich way. However, if the raycast is at exactly 90 degrees to the RayCast then the output is zero. Like this:
Vector2(1, 0).dot(Vector2(0, 1))
is:
1 * 0 = 0
0 * 1 = 0
0 + 0 = 0
But once the normal and the raycast aren't precisely aligned (like they will if you hit a circle to the left or right) then the rays will be misaligned orthogonally and you'll get a positive / negative value depending on whether it's to the left or right.
Wow, I wrote a lot!