So my problem is i can’t find any ray casting tutorials or code that are in js and are for 2d. I want my game to be a top down sort of stab things and they die. But, i can’t figure out ray casting for the life of me.
There is a 2D raycast method in unity. Physics2D.Raycast should do what you want. The example code on that page is in js.
It really all depends on the axis that your game is running in. Now I haven’t double checked this but from my limited knowledge all the 2D functions or Vector2’s run on X and Y. You could always use regular raycast and use it in a 2D way, you just have to give the unused axis the value of zero. Here’s an example, I’m currently running a 2D scene in unity but it runs on the Z and Y axis because I like using Z as my forward. I have to use Vector3 since Vector2 doesn’t use the Z axis. I just give X a value of zero so it get’s unused.