Mz3
1
I’m sure there’s answer for this somewhere but I can’t for the life of me find one.
I’m attempting to cast a 2D Raycast/Linecast from my player in the direction of my mouse, A straight line from my character that heads toward my mouse and continues on in that direction until a certain distance has been surpassed.
A C# solution would be most appreciated
This should work
RaycastHit2D hit = Physics2D.Linecast(transform.position, Input.mousePosition, distance);
That will return the first object hit.
If you want all objects, simply return an array
RaycastHit2D[] hits = Physics2D.LinecastAll(transform.position, Input.mousePosition, distance);
simply replace distance for whatever you want.