acreol
(acreol)
July 25, 2019, 3:46am
#1
My Roblox’s CurrentCamera NearPlaneZ is -.1 but other cameras have -.5 NearPlaneZ
And since NearPlaneZ is read-only, the camera methods such as WorldToViewportPoint
are all inaccurate and useless with non CurrentCameras (which means we have to rewrite the methods ourselves but I don’t know all this linear algebra )
1 Like
I think those inaccurate results are caused by invalid ViewportSize. You can use the following script as a workaround.
local worldToScreenPoint = function(viewportFrame, worldPoint)
local camera = viewportFrame.CurrentCamera
local halfWidth = viewportFrame.AbsoluteSize.X / 2
local halfHeight = viewportFrame.AbsoluteSize.Y / 2
local pCamSpace = camera.CFrame:PointToObjectSpace(worldPoint)
local planeDistance = -halfHeight / math.tan(camera.FieldOfView * math.pi / 360)
local nPlaneY = pCamSpace.Y / pCamSpace.Z * planeDistance;
local nPlaneX = pCamSpace.X / pCamSpace.Z * planeDistance;
local visible = pCamSpace.Z < 0 and math.abs(nPlaneX) < halfWidth and math.abs(nPlaneY) < halfHeight
return Vector3.new(halfWidth + nPlaneX, halfHeight - nPlaneY, -pCamSpace.Z), visible
end
3 Likes
acreol
(acreol)
July 25, 2019, 11:45pm
#3
Is NearPlaneZ always -.5 not a bug though?
Camera | Documentation - Roblox Creator Hub says it is -.5 on some devices, so it can’t just be because the viewportsize is 1,1
It is a bug. I will fix it. Thanks for your report.
2 Likes
system
(system)
Closed
October 25, 2022, 10:07pm
#5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.