Vector2 curMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mouseDir = curMousePosition * 10.0f;
RaycastHit2D hit = Physics2D.Linecast(player.transform.position, mouseDir);
if (hit.collider != null)
{
Debug.Log("cur mouse point = " + curMousePosition);
Debug.Log("mouse dir point = " + mouseDir);
Debug.Log("hit point = " + hit.point);
Debug.DrawLine(player.transform.position, curMousePosition, Color.red);
Debug.DrawLine(player.transform.position, mouseDir, Color.yellow);
Debug.DrawLine(player.transform.position, hit.point, Color.blue);
}
The red line is from the player to the current mouse coordinates.
The yellow line is from the player to the current mouse coordinate multiplied by 10.0f.
The blue line is from the player to the Collider Hit coordinate.
My intention is to draw the Linecast to the coordinates of the mouse coordinate multiplied by 10.0f,
A yellow line is drawn on the extension line of the red line, and there is also the Collider, so we expected to return the Collider coordinates on the extension line of the red line.
However, the result of [Mouse coordinate multiplication 10.0f] and [HIT POINT] is strange
I understand that to understand Linecast, I draw a hypothetical line between two other coordinates and return it if there is a Collider.
Am I misunderstanding something?