0 votes

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

in Engine by (196 points)
edited by

1 Answer

+1 vote
Best answer

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):
by (103 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.