This commit is contained in:
CortexCore
2025-03-24 14:42:40 +08:00
parent 18239a5ae4
commit 9845d20f7f
99 changed files with 5418 additions and 5512 deletions

View File

@@ -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;