Reproduction Steps
Using WorldToViewportPoint does not return correct offset values for use on screengui’s
This image shows that it should convert a 3D point in the world, to a 2D space, with the X and Y being the pixels on the screen
https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToViewportPoint
local vector, onScreen = Camera:WorldToViewportPoint(WorldModel.BottomHalf.Position)
print(vector)
script.Parent.Card.Position = UDim2.fromOffset(vector.X, vector.Y)
Expected Behavior
The 3D space to return a 2D point, with offset
Actual Behavior
It returns seemingly scale degrees
0.5, 0.62929719686508, 6.0750036239624
If I do .fromScale, and plug it in, it works for this use case, but if the documentation states it should be pixels, then I want and expect to see pixels returned. Prime example being
local TopLeft = Vector3.new(
WorldModel.BottomHalf.Position.X + (WorldModel.BottomHalf.Size.Z / 2),
WorldModel.BottomHalf.Position.Y,
WorldModel.BottomHalf.Position.Z - (WorldModel.BottomHalf.Size.X / 2)
)
local BottomRight = Vector3.new(
WorldModel.BottomHalf.Position.X - (WorldModel.BottomHalf.Size.Z / 2),
WorldModel.BottomHalf.Position.Y,
WorldModel.BottomHalf.Position.Z + (WorldModel.BottomHalf.Size.X / 2)
)
TopLeftPart.Position = TopLeft -- The yellow part
BottomRightPart.Position = BottomRight -- The green part
local TopLeftVector = Camera:WorldToViewportPoint(TopLeft)
local BottomRightVector = Camera:WorldToViewportPoint(BottomRight)
print("Size", BottomRightVector.X, TopLeftVector.X)
prints
Size 1.0583291053772 -0.058329164981842 - Client - LocalScript:139
Even tho this is the vector3s
So no reason for either BottomRightVector or TopLeftVector to have positions that are off screen, when they are clearly on screen. Even adding the onScreen check, it says false, but I can clearly see the 2 points on screen.
Workaround
No
Issue Area: Engine
Issue Type: Other
Impact: Very High
Frequency: Constantly