Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I get the closest point on a part, to a position?

Asked by 3 years ago

I'm trying to figure out how to get the closest (point) position on a part to another position in the game. I'm not exactly sure how to do it. I've tried to get the left, right and center of the part and get the closest, but that's not what I'm trying to do

I've tried also this:

local start = pathPart.CFrame
    *CFrame.new(pathPart.Size.X/3, pathPart.Size.Y/2,(pathPart.Size.Z/2))
    *CFrame.Angles(0, math.rad(180), 0) 

local finish = pathPart.CFrame
    *CFrame.new(pathPart.Size.X/3*-1, pathPart.Size.Y/2,(pathPart.Size.Z/2)*-1)
    *CFrame.Angles(0,0,0)

    local ray = Ray.new(start.Position, (finish.Position - start.Position).unit )

    local closestPoint = ray:ClosestPoint(pathPart.Position)

    local distanceAway = (house.PrimaryPart.Position - closestPoint).Magnitude
    warn(distanceAway)

That's not quite working either. I'm just not certain what I'm doing wrong. Any help appreciated.

I'm trying to get the distance from the house to the closest point on the path in front of the house: Click here

Answer this question