The problem appears to be that the RaycastHit2D is continually
returning a point of (0,0)
This happens if the raycast's origin is already within or in contact with an object. In these cases, the raycast's normal will be opposite to the direction it was cast, and it's result will be zero.
Please take a look at the Physics2D.Raycast documentation; specially this paragraph:
Additionally, this will also detect Collider(s) at the start of the
ray. In this case the ray is starting inside the Collider and doesn't
intersect the Collider surface. This means that the collision normal
cannot be calculated in which case the collision normal returned is
set to the inverse of the ray vector being tested. This can easily be
detected because such results are always at a RaycastHit2D fraction of
distance should definitely not be set for
infinity. Raycasts are relatively expensive, and so it's bad practice and very unrecommended to do it the way you are, currently.
When dealing with raycasts, you should make the parameters (/resulting raycast) "as little as possible to get the job done".
Also, considering you are a self-admitted Unity-noob, and that's a strange way to do things if it's indeed correct, do note that the
int for the raycast's
Layermask is a layermask's bit-wise flags set, not a layer's index. If the value
8 is not a precalculated bit-mask supposed to represent a set of layers, then it's probably wrong.
Edit: To easily convert from index to layermask, you can simply do the bitwise operation to shift bits left to the correct index position. In this case, that would be
1 << 8. Where
1 would be the binary/bit-wise
<< 8 shifts that binary
1 8 places to the left, resulting in the correct bit-wise mask: