Right now I am trying to make it where you hover in a frame on a gui is where a part goes inside a part like say you hover over a specific corner it hovers in that corner.
I have created something but its highly inaccurate and it will just not match up
if i change the frames or parts size I want it still to match up completel GoalieTest.rbxl
To map GUI coordinates to the position on the surface of a part, do this:
-- map function for convenience.
-- Similar to lerp but it takes an expanded input range
local function map(num, min_from, max_from, min_to, max_to)
return min_to+(max_to-min_to)*(num-min_from)/(max_from-min_from)
end
-- Define these somehow
local part_size = the_part_size -- Vector3
local part_cframe = the_part_cframe -- CFrame
local mouse_pos = mouse_position_on_screen - gui_absolute_position -- Vector2
local gui_size = gui_absolute_size -- Vector2
-- Depending on your GUI and Part setup, the axes may need to be negated,
-- rearranged, or swapped. Currently the Vector3's X axis is negated by
-- swapping positive and negative on the last two inputs.
-- X on the GUI becomes Z on the part and Y on the GUI becomes X on the part.
local relative_pos = Vector3.new(
map(mouse_pos.Y, 0, gui_size.Y, part_size.X/2, -part_size.X/2),
part_size.Y/2,
map(mouse_pos.X, 0, gui_size.X, -part_size.Z/2, part_size.Z/2)
)
local world_pos = part_cframe:PointToWorldSpace(relative_pos)