Thanks for the code saifix. I will try to understand the code instead of just copy and paste.
Could you please give a more detailed explanation of the code? For instance, what is Vec2? The arg to direction, is that X Y coordinates to an object?
Also, your code just check a straight line, right?
Vec2 is a vector made up of 2 components, x & y. The arguments are the direction which the casted ray is traveling in, if it were (-1, 0) it'd test a straight line starting going to the left of the unit and if it were (0, 1) it'd test a line traveling up from the unit.
Yes, it only checks a straight line.