How to get the closest point to a player?

I want my character to look at the closest surface it has each frame, I’m using IK and attachments.

But my issue is, how would I get the closest “point” to the player? Considering there might be many parts near me

Kinda like this

help :cry:

There’s a fancy built-in method that does what you want!
BasePart:GetClosestPointOnSurface()

And to get the closest part, just filter through the closest by their positions, roughly accounting for their size/bounding box if necessary. Or if you’re going for something in the player’s perspective, you can use raycasts.

2 Likes

I had absolutely no idea this method existed, it’s perfect, thanks! :grin:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.