[Godot 2.1.4] Getting strange results from unprojecting 3D positions

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By woopdeedoo

I’m getting weird results from unprojecting positions from the camera in 3D with camera.unproject_position( pos_vec3 ). I’m unprojecting the vertices from a cube mesh I have in my scene. Everything seems to work fine when I’m outside the mesh and all its vertices are within view, but when I’m inside the mesh the unprojections are weird.

For example, when looking upward so the bottom face is totally outside the screen below the camera’s visibility (as in the image below), unprojecting the vertices from the bottom face gives me Y values that don’t make sense:
>>> [(-657, 4191), (1211, 224), (480, 401), (-973, -583)]

The screen is 800 pixels tall, so I’d suppose all the Y values would be greater than 800.

Why would the camera be unprojecting them like that?

enter image description here

:bust_in_silhouette: Reply From: potato

Did you ever figure this out?

I’m having a similar issue - I’m unprotecting the camera position to place UI over a 3d point. Trouble is, when the camera faces AWAY from the object, the UI still shows - it’s as though it thinks the camera view is both forwards and backwards.

Edit: I have found a workaround is to manually hide the UI when it is behind the camera with:

if get_viewport().get_camera().is_position_behind(ui_position_3d):