Camera:WorldToScreenPoint() misplacing

So, uh, hello
I was exploring the camera:worldtoscreenpoint() thing in studio, you know, which puts a UI object over a world object on your screen, but when I use it, it has an offset, and it’s not centered. Here is the little function that does it:

function setPoint(obj)
	local position, isIn = camera:WorldToScreenPoint(obj.Position)
	if isIn then
		GUI.TargetLock.Visible = true
		GUI.TargetLock.Position = UDim2.fromOffset(position.X, position.Y)
	end
end

The end result comes like that:

and it seems to be offsetting more, the further my camera is.

Since both Udim2 offset is measured in pixels, and worldtoscreenpoint X and Y return pixels, I see no reason why would this be the problem (correct me if I’m wrong please, and if I am wrong, then recommend a decent conversion to Udim please).

Your anchor point is 0,0 which is the top left. Set it to .5, .5

thanks a lot, why didn’t I think of that… uh, sometimes I forget about the default properties that need to be set.

1 Like