I have a point A (x, y, z), and a Box: Center (x, y, z), Size (Width, Height)
How to get the closest point in the box from the point A ?
In Unity I can create a bound, and I can find the non-rotated position like that:
Bounds bounds = _mesh.bounds; Vector3 closestPoint = bounds.ClosestPoint(pointA); But then If the bound is rotated, the result is not correct. So I have 2 options:
Find the way to rotate my closestPoint from the pivot. Find the math formula myleft.
If someone can help ! thanks.
EDIT: here a video: the red point is the one find with bound.ClosestPoint the yellow point is the one find with:
Vector3 closestPointInverse = _currentTarget.InverseTransformPoint(closestPoint); I have also tryed to do my own rotateFromPivot function:
public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles) { return Quaternion.Euler(angles) * (point - pivot) + pivot; } When I use it, I get the same result with the InverseTransformPoint method.
