I wanted to know how I can get the same result this function gives in Unity 2018.3 where it is not avaliable yet:
https://docs.unity3d.com/2019.1/Documentation/ScriptReference/Collider2D.ClosestPoint.html
I wanted to know how I can get the same result this function gives in Unity 2018.3 where it is not avaliable yet:
https://docs.unity3d.com/2019.1/Documentation/ScriptReference/Collider2D.ClosestPoint.html
I had this problem today, I'm also using 2018.3. Here's a helper function here that supplants collider2D.ClosestPoint. Edit the colliders as you need.
public static class Collider2DExtension
{
/// <summary>
/// Return the closest point on a Collider2D relative to point
/// </summary>
public static Vector2 ClosestPoint(this Collider2D col, Vector2 point)
{
GameObject go = new GameObject("tempCollider");
go.transform.position = point;
CircleCollider2D c = go.AddComponent<CircleCollider2D>();
c.radius = 0.1f;
ColliderDistance2D dist = col.Distance(c);
Object.Destroy(go);
return dist.pointA;
}
}
sourced it from this thread: https://forum.unity.com/threads/get-closest-point-of-collider2d.225120/