ClosestPoint
Returns a point on the perimeter of the Collider that is closest to the specified position.
Read time 1 minuteLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.Physics2DModule
ClosestPoint(Vector2, Collider2D)
Returns a point on the perimeter of the that is closest to the specified .
Colliderpositionpublic static Vector2 ClosestPoint(Vector2 position, Collider2D collider)
Parameters
The position from which to find the closest point on the specified .
ColliderReturns
Type | Description |
|---|---|
| Vector2 | A point on the perimeter of the |
Remarks
This function provides the ability to calculate the closest point of a specified to the perimeter of any Collider2D type.
positionIn the case where the is inside the or the is disabled, then the input is returned instead.
positionColliderColliderpositionClosestPoint(Vector2, Rigidbody2D)
Returns a point on the perimeter of all enabled Colliders attached to the that is closest to the specified .
rigidbodypositionpublic static Vector2 ClosestPoint(Vector2 position, Rigidbody2D rigidbody)
Parameters
The position from which to find the closest point on the specified .
rigidbodyThe Rigidbody on which to find the closest specified .
positionReturns
Type | Description |
|---|---|
| Vector2 | A point on the perimeter of a Collider attached to the |
Remarks
This function provides the ability to calculate the closest point of a specified to the perimeter of any enabled Collider2D type attached to the specified Rigidbody2D.
positionIn the case where the is inside any of the enabled Collider2D attached to the , the input is returned instead.
positionrigidbodyposition