How can I get the distance between two parts based on their outer box instead of the middle of both parts?

Hi, I am currently trying to write a custom character controller from scratch, including the movement. A current issue I face is that the player will still be pushed against the wall when they are touching it, which causes them to somewhat stick to the wall. I would like to determine how close they are to the wall they are walking towards (which I can figure out with raycasts), but I cannot use .Magnitude as it would give me the distance between the centre of both points, whereas I need to know how close they are based on the outer box. For example, this should be considered very close (within 0.1 studs):
image
I’ve tried using other raycasts to get the position of the outer box but it’s near impossible to determine which part of the body I should be using to determine magnitude. Is there a way to determine which point of my character (HumanoidRootPart) is the closest to the wall?

1 Like

Offset middle by for example: part.Size.Z/2

then you can use Magnitude. You can do magnitude for every axis and find closest one. Closest one would be the one facing wall

I’m not trying to find which face is closer to the wall, I’m trying to determine which exact point on the Humanoid is the closest to the wall. This requires me to know exactly which point is the closest so I know exactly where to send a ray from, not just the closest face.