#Help with advanced closest point function

14 messages · Page 1 of 1 (latest)

covert kestrel
#

does anyone know how i can make a closest point function like this? (i know how to get the closest part from the mouse but not this) i searched it up on the dev forums but the closest i got was some very weird maths that didn't help me at all.

Note: the closest point (green part) is inside the the closestpart on the center and moving up and down on the Y axis, the way i think this is done is by getting the closest part and applying some weird maths on it to get the Y axis inside the part but i really dont know

Also i tried asking the person who made this video but they wont tell me

tight pike
covert kestrel
#

up and down

tight pike
#

Okay

#

Do you know how to raycast?

covert kestrel
#

yes

tight pike
#

Forget that for now

#

Can i see the function for closest part?

covert kestrel
#

sure one second

#
local function getClosestPart()
    local distance, closestPart = math.huge, nil
    local mousePos = UserInputService:GetMouseLocation()

    for _, part in ipairs(Dummy:GetChildren()) do
        if part:IsA("BasePart") or part.ClassName == "MeshPart" then
            local screenPos, onScreen = Camera:WorldToViewportPoint(part.Position)
            if onScreen then
                local mag = (Vector2.new(screenPos.X, screenPos.Y) - mousePos).Magnitude
                if mag < distance then
                    closestPart = part
                    distance = mag
                end
            end
        end
    end

    return closestPart
end
half jewelBOT
#

studio** You are now Level 1! **studio

tight pike
covert kestrel
#

no problem man