Ok... I am quite the novice when it comes to game related math, especially in the 3D realm. So I shall try to convey my problem as clearly as possible, since I do not know much of the terminology.
I have a Camera in 3D space, this camera can be located at any x,y,z and it can face any direction valid for a FPS view.
I have a target, the target can be at any location in 3D space along the x,y,z however the target will be STATIC and non movable.
I would like to be able to have my camera position itself in front of the target so that the target will appear a certain size and location on the 2D render screen.
I found online a function, when when supplied with variables of x,y (location of target to be displayed on 2D screen) and height (the height the target should display on the 2D screen) the function will return a Vector3 stating where the target should be placed in 3D space, so that it will render at the x,y at desired height on the 2D render screen.
The problem I am having is converting that Vector3 into something that I can use to position my Camera (since my target is stable) in the correct position to get the same result.
This is what I am doing so far... the code is in Lua
-- This line is calling the function I found online, I am requesting a Vector3 position so the target will be shown on the 2D render at position screenW/2, screenH/2 (so that should be in center of screen) and I want the object to appear to be .5 the size of my screen's height so thats the second screenH/2. The last argument is the unit size of the object (2 units high)
local pos = ScreenSpace.ScreenToWorldByHeight(screenW/2,screenH/2,screenH/2, 2)
Now the result is ... pos = (0,0,-2) -- Meaning i need to have the target positioned -2 away from my camera on the Z axis to display as needed.
This is the same result no matter which way my camera is facing, so I know the result is based off of my camera's .. facing vector?
So I tried this to get my new camera position...
newCamPos = TargetPosition - pos
This however, causes my camera to be positioned at the targets location offset by +2 on the Z axis, when in reality, I need it to be +2 on the Z axis in relation to how the Target is facing, the targets facing vector.
So I am lost... is there an easier way to do this? What terms should I search for? Or if you have any tips or tricks to share that would be great.