Hey, thanks for the solution! I only had to modify it a little cuz i was having some weird bugs, but now its working perfectly, there is only a small problem.
After i finished adding the bordersnap functionaly, it was working perfectly, when the blip got far away, it would clamp to the borders, but then i decided to add rotation to the minimap camera, and it broke the bordersnap
here is footage of the problem
https://drive.google.com/file/d/1BsIjYZhumsOUb_-od1FlbLH-RPzcE_Um/view
here is the current code, its just a test
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local HRP = character:WaitForChild("HumanoidRootPart")
local raycast2d = require(player.PlayerGui:WaitForChild("RayCast2"))
local playerCamera = workspace.CurrentCamera
local distance = 1500
local fov = 1
local minimapFrame = script.Parent.Minimap
local part = minimapFrame.Part
local testBlip = minimapFrame.Blip
local blipPosition = testBlip.Position
local minimapCamera = Instance.new("Camera")
minimapCamera.Parent = workspace
minimapCamera.FieldOfView = fov
minimapFrame.CurrentCamera = minimapCamera
local height = math.tan(math.rad(minimapCamera.FieldOfView/2)) * 2 * distance
local width = height * (minimapFrame.AbsoluteSize.X / minimapFrame.AbsoluteSize.Y)
part.Size = Vector3.new(width, 100, height)
part.Parent = workspace
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Whitelist
params.FilterDescendantsInstances = {part}
game:GetService("RunService").RenderStepped:Connect(function()
local heading = 0
local direction = playerCamera.CFrame.LookVector
heading = math.atan2(direction.X, direction.Z)
heading = math.deg(heading)
part.Position = HRP.Position
minimapCamera.CFrame = CFrame.lookAt(HRP.Position + Vector3.new(0, distance, 0), HRP.Position) * CFrame.Angles(0, 0, math.rad(-90 + heading))
local blipDistanceY = (HRP.Position * Vector3.new(0, 0, 1) - blipPosition * Vector3.new(0, 0, 1)).Magnitude
if blipDistanceY > height/2 - testBlip.Size.Z/2 and blipPosition.Z > HRP.Position.Z then
local ray = raycast2d.new(Vector2.new(minimapFrame.AbsolutePosition.X, minimapFrame.AbsolutePosition.Y), Vector2.new(200, 200))
local hit, pos = ray:Cast(script.Parent, {minimapFrame})
ray.Visible = true
print(hit, pos)
testBlip.Position = Vector3.new(testBlip.Position.X, 0, HRP.Position.Z + height/2 - testBlip.Size.Z/2)
elseif blipDistanceY > height/2 - testBlip.Size.Z/2 and blipPosition.Z < HRP.Position.Z then
testBlip.Position = Vector3.new(testBlip.Position.X, 0, HRP.Position.Z - height/2 + testBlip.Size.Z/2)
end
local blipDistanceX = (HRP.Position * Vector3.new(1, 0, 0) - blipPosition * Vector3.new(1, 0, 0)).Magnitude
if blipDistanceX > width/2 - testBlip.Size.X/2 and blipPosition.X > HRP.Position.X then
testBlip.Position = Vector3.new(HRP.Position.X + width/2 - testBlip.Size.X/2, 0, testBlip.Position.Z)
elseif blipDistanceX > width/2 - testBlip.Size.X/2 and blipPosition.X < HRP.Position.X then
testBlip.Position = Vector3.new(HRP.Position.X - width/2 + testBlip.Size.X/2, 0, testBlip.Position.Z)
end
end)
my thinking was to use some kind of 2d raycast to calculate the offset that it needs to have to clamp it right to the border