This isn't what I need. This code converts 2d screen coordinates into 3d world coordinates and places an object at that location.

What I need is help with code that places a view entity at the mouse location in the view, not the 3d world; the thing that gets me is that the x/y/z locations for a view entity are different than the x/y/z locations in the 3d world.

X is the depth, how close the view entity is to the screen.

Y is the horizontal placement, setting it to 0 puts the view entity in the middle of the screen on the Y axis instead of at the left side.

Z is the vertical placement, setting it to 0 puts the view entity in the middle of the screen on the Z instead of the top.

So what I need help with is converting the regular screen coordinates (mouse_pos.x, mouse_pos.y) to a number that can place the view entity at the mouse position.

What I tried to do is set the view entity to mouse_pos.x and mouse_pos.y, needless to say that lead to a messed up result. I then subtracted half of the screen width and height which worked, but the vector was inverted: pushing the mouse left moved the view entity right, moving the mouse up moved the view entity down, etc... I tried to invert the vector again to make negatives positive and positives negative, but the result was the view entity being really messed up.