Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity find closest point on line

public Vector2 FindNearestPointOnLine(Vector2 origin, Vector2 direction, Vector2 point)
{
    direction.Normalize();
    Vector2 lhs = point - origin;

    float dotP = Vector2.Dot(lhs, direction);
    return origin + direction * dotP;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #unity #find #closest #point #line
ADD COMMENT
Topic
Name
1+2 =