How to get 2D point on screen for viewport 3D position

I have tried multiple solutions but none seem to work for what i am doing for some reason.

1 Like

ScreenPointToRay

No, i want to get a 2D position from a 3D position within the viewport.

Im still not sure what you meant in your last post, why a viewport frame would be 1 pixel by 1 pixel
Are you trying to make a rendering system using pixels or something?

No, in my last post i told you that camera:WorldToViewportPoint() only works with the default camera, the one in the workspace, i just want to get a 2D position from a 3D point in the viewport to place a gui object there.

https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToScreenPoint
https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToViewportPoint

These should help.

Edit: Didn’t read the reply above. I don’t think it is possible to do so without using those functions? Unless, there is some fancy way to do it without WorldToScreenPoint/ViewportPoint.

2 Likes

Ive been able to recreate your problem I think

The camera defaults to a viewport size of 1,1 (this is a readonly property), when the normal camera usually has a viewportsize equal to your screen
Created camera:
image
Default camera:
image

ViewportFrame size proportional to 1,1

ViewportFrame size not proportional to 1,1

Ill try to come up with a solution but just for clarity for others trying to solve the problem, this is what hes talking about from what I can understand

1 Like

It looks like you can just fix it by doing:

((x-0.5)*viewportFrame.AbsoluteSize.Y/viewportFrame.AbsoluteSize.X+0.5,0,y,0) 

Kinda a weird fix but it seems to work

This is the return of the function right?

also this shows up in script analysis for some reason
image
image

Just delete one of the parentheses from the UDim2.new and it should hopefully work

Lol i just did that and then you said it :exploding_head:
Alright, now to test it.

I inputted 5.64, 5.59, -60 as the position, visible within the viewportFrame, got
{0.512151718, 0}, {-0.203799173, 0}
as the position.


Red cube for reference

Maybe if i could generate the camera locally so it had the correct viewportsize property, then I could replicate it to the server?

Turns out the function ony works client side, so after setting a remote function up it worked.

1 Like