So I’m trying to make effectively a compass that always points to Point A on your screen. I’m doing this by finding the unit vector of A - Player and then mapping that onto a UDim2
One problem I’m aware of is that right now it uses Camera.p, meaning if I’m looking west by my camera position is east of the object, it’ll reflect the position of the camera (and not the Look Vector as it should).
Another problem I’m aware of is it just doesn’t accurate map the position. Any help (and explanation of what I did wrong) is very welcome!
local Radius = 50
local Players = game:GetService("Players")
wait(1)
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Camera = workspace.CurrentCamera
local A = workspace:WaitForChild("A")
function Vec3ToVec2(Vec3)
return Vector2.new(Vec3.x, Vec3.z - (Vec3.z * 2)).unit
end
function FindUnitVector(A, B)
return (B - A).unit
end
local ScreenGui = Instance.new("ScreenGui", PlayerGui)
local CentrePoint = Instance.new("Frame", ScreenGui)
local Image = Instance.new("ImageLabel", CentrePoint)
CentrePoint.Size = UDim2.new(0, 0, 0, 0)
CentrePoint.Position = UDim2.new(.5, 0, .5, 0)
Image.Size = UDim2.new(0, 20, 0, 20)
while wait()do
local aVec = Vec3ToVec2(A.Position)
local bVec = Vec3ToVec2(Camera.CFrame.p)
local unitVec = FindUnitVector(aVec, bVec)
Image.Position = UDim2.new(0, unitVec.X * Radius, 0, unitVec.Y * Radius)
end