I am trying to play an ui on the players mouse relative to the 3d world and been using this to convert but it is off screen. I am trying to mark where the user clicked, since I have their camera frozen to the side like it is 2d.
function WorldToScreen(Pos) --This function gets a World Position (Pos) and returns a Vector2 value of the screen coordinates
local point = camera.CoordinateFrame:pointToObjectSpace(Pos)
local aspectRatio = mouse.ViewSizeX / mouse.ViewSizeY
local hfactor = math.tan(math.rad(camera.FieldOfView) / 2)
local wfactor = aspectRatio*hfactor
local x = (point.x/point.z) / -wfactor
local y = (point.y/point.z) / hfactor
return Vector2.new(mouse.ViewSizeX * (0.5 + 0.5 * x), mouse.ViewSizeY * (0.5 + 0.5 * y))
end
The user will click and I will put an x on their screen where they clicked and I need to save the 3d world space version. Which I have already so I was going to convert Edit: I accidentally got it working