1
This commit is contained in:
@@ -6,6 +6,28 @@ using UnityEngine;
|
||||
|
||||
namespace BITKit.Physics
|
||||
{
|
||||
public static class PhysicsExtensions
|
||||
{
|
||||
public static bool TryGetClosestPointFromCollider(this Collider collider,Vector3 point,out Vector3 closestPoint)
|
||||
{
|
||||
closestPoint = default;
|
||||
switch (collider)
|
||||
{
|
||||
case BoxCollider:
|
||||
case SphereCollider:
|
||||
case CapsuleCollider:
|
||||
case MeshCollider { convex: true }:
|
||||
case TerrainCollider:
|
||||
closestPoint = collider.ClosestPoint(point);
|
||||
return true;
|
||||
case MeshCollider { convex: false } meshCollider when new GetClosestPointFromMesh(meshCollider.sharedMesh,point).TryGetValue(out closestPoint,out _):
|
||||
closestPoint = collider.transform.TransformPoint(closestPoint);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public readonly struct GetClosestPointFromMesh:IClosePointProvider
|
||||
{
|
||||
private readonly Vector3 _position;
|
||||
|
Reference in New Issue
Block a user